CTxMemPool::FindScriptPubKey to search unconfirmed UTXOs

This commit is contained in:
Luke Dashjr 2016-11-13 19:46:45 +00:00
parent 401bfc1752
commit d5f9eea818
2 changed files with 18 additions and 0 deletions

View File

@ -803,6 +803,21 @@ std::vector<CTxMemPool::indexed_transaction_set::const_iterator> CTxMemPool::Get
return iters;
}
void CTxMemPool::FindScriptPubKey(const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results) {
LOCK(cs);
for (const CTxMemPoolEntry& entry : mapTx) {
const CTransaction& tx = entry.GetTx();
const Txid& hash = tx.GetHash();
for (size_t txo_index = tx.vout.size(); txo_index > 0; ) {
--txo_index;
const CTxOut& txo = tx.vout[txo_index];
if (needles.count(txo.scriptPubKey)) {
out_results.emplace(COutPoint(hash, txo_index), Coin(txo, MEMPOOL_HEIGHT, false));
}
}
}
}
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
}

View File

@ -40,6 +40,7 @@
#include <vector>
class CChain;
class CScript;
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
@ -696,6 +697,8 @@ public:
std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
std::vector<TxMempoolInfo> infoAll() const;
void FindScriptPubKey(const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results);
size_t DynamicMemoryUsage() const;
/** Adds a transaction to the unbroadcast set */