Last active
August 29, 2015 14:16
-
-
Save dexX7/b768f1c9b2fcbd115939 to your computer and use it in GitHub Desktop.
Update block height of entry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... 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