CCoinsMap::iterator CCoinsViewCache::FetchCoins(const uint256 &txid) { CCoinsMap::iterator it = cacheCoins.find(txid); if (it != cacheCoins.end()) return it; CCoins tmp; if (!base->GetCoins(txid,tmp)) return cacheCoins.end(); CCoinsMap::iterator ret = cacheCoins.insert(it, std::make_pair(txid, CCoins())); tmp.swap(ret->second); return ret; }
/** * Construct a dummy tx that provides the given script as input * for further tests in the given CCoinsView. The txid is returned * to refer to it. The "index" is always 0. The output's * value is always set to 1000 COIN, since it doesn't matter for * the tests we are interested in. * @param scr The script that should be provided as output. * @param nHeight The height of the coin. * @param view Add it to this view. * @return The txid. */ static uint256 addTestCoin (const CScript& scr, unsigned nHeight, CCoinsViewCache& view) { CMutableTransaction mtx; mtx.vout.push_back (CTxOut (1000 * COIN, scr)); const CTransaction tx(mtx); CCoinsModifier entry = view.ModifyCoins (tx.GetHash ()); *entry = CCoins (tx, nHeight); return tx.GetHash (); }
std::map<uint256,CCoins>::iterator CCoinsViewCache::FetchCoins(const uint256 &txid) { std::map<uint256,CCoins>::iterator it = cacheCoins.lower_bound(txid); if (it != cacheCoins.end() && it->first == txid) return it; CCoins tmp; if (!base->GetCoins(txid,tmp)) return cacheCoins.end(); std::map<uint256,CCoins>::iterator ret = cacheCoins.insert(it, std::make_pair(txid, CCoins())); tmp.swap(ret->second); return ret; }