Skip to content

Commit ae2af54

Browse files
committed
[Refactoring] Add GetCoinDepth utility function to CCoinsViewCache
1 parent 30d353e commit ae2af54

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/coins.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ double CCoinsViewCache::GetPriority(const CTransaction& tx, int nHeight, CAmount
268268
return tx.ComputePriority(dResult);
269269
}
270270

271+
int CCoinsViewCache::GetCoinDepthAtHeight(const COutPoint& output, int nHeight) const
272+
{
273+
const Coin& coin = AccessCoin(output);
274+
if (!coin.IsSpent())
275+
return nHeight - coin.nHeight + 1;
276+
return -1;
277+
}
278+
271279
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_SIZE_CURRENT / ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION); // TODO: merge with similar definition in undo.h.
272280

273281
const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)

src/coins.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ class CCoinsViewCache : public CCoinsViewBacked
285285
*/
286286
double GetPriority(const CTransaction& tx, int nHeight, CAmount &inChainInputValue) const;
287287

288+
/*
289+
* Return the depth of a coin at height nHeight, or -1 if not found
290+
*/
291+
int GetCoinDepthAtHeight(const COutPoint& output, int nHeight) const;
292+
293+
288294
private:
289295
CCoinsMap::iterator FetchCoin(const COutPoint& outpoint) const;
290296

0 commit comments

Comments
 (0)