Skip to content

Instantly share code, notes, and snippets.

@dexX7
Last active August 29, 2015 14:16
Show Gist options
  • Save dexX7/b768f1c9b2fcbd115939 to your computer and use it in GitHub Desktop.
Save dexX7/b768f1c9b2fcbd115939 to your computer and use it in GitHub Desktop.
Update block height of entry
// ... somewhere ...
static int getHeight(const uint256& hash)
{
CTransaction tx;
uint256 hashBlock = 0;
if (!GetTransaction(hash, tx, hashBlock, true))
return -1; // not found!
if (hashBlock != 0) {
std::map<uint256, CBlockIndex*>::const_iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second) {
CBlockIndex* pindex = (*mi).second;
if (chainActive.Contains(pindex))
return pindex->nHeight; // confirmed! SUCCESS!
}
}
{
LOCK(mempool.cs);
if (!mempool.exists(hash))
return -1; // conflicting!
}
return 0; // still unconfirmed
}
void TXHistoryDialog::UpdateHistory()
{
// ...
// loop over txHistoryMap and update the confirmations icon for each transaction
for (HistoryMap::iterator it = txHistoryMap.begin(); it != txHistoryMap.end(); ++it) {
const uint256& txid = it->first; // grab txid
HistoryTXObject& htxo = it->second; // grab the transaction <- no copy, but reference (!)
// might be confirmed now
if (htxo.blockHeight == 0)
htxo.blockHeight = getHeight(txid);
// conflicting or orphaned
if (htxo.blockHeight < 0)
htxo.valid = false;
int confirmations = 0;
if (htxo.blockHeight > 0)
confirmations = (chainHeight + 1) - htxo.blockHeight;
// setup the appropriate icon
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment