Allow pours to be anchored to intermediate treestates of a transaction.

This commit is contained in:
Sean Bowe 2016-05-26 14:00:46 -06:00
parent 8048f4c048
commit 6c59778acb
1 changed files with 13 additions and 3 deletions

View File

@ -386,6 +386,8 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
bool CCoinsViewCache::HavePourRequirements(const CTransaction& tx) const
{
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
BOOST_FOREACH(const CPourTx &pour, tx.vpour)
{
BOOST_FOREACH(const uint256& serial, pour.serials)
@ -398,11 +400,19 @@ bool CCoinsViewCache::HavePourRequirements(const CTransaction& tx) const
}
ZCIncrementalMerkleTree tree;
if (!GetAnchorAt(pour.anchor, tree)) {
// If we do not have the anchor for the pour,
// it is invalid.
auto it = intermediates.find(pour.anchor);
if (it != intermediates.end()) {
tree = it->second;
} else if (!GetAnchorAt(pour.anchor, tree)) {
return false;
}
BOOST_FOREACH(const uint256& commitment, pour.commitments)
{
tree.append(commitment);
}
intermediates.insert(std::make_pair(tree.root(), tree));
}
return true;