diff --git a/src/claimtrie.cpp b/src/claimtrie.cpp index c7ebcc6a4..743bda4ed 100644 --- a/src/claimtrie.cpp +++ b/src/claimtrie.cpp @@ -526,31 +526,41 @@ claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const return allClaims; } -//return effective amount form claim, retuns 0 if claim is not found +//return effective amount from claim, retuns 0 if claim is not found CAmount CClaimTrie::getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const { - claimsForNameType claims = getClaimsForName(name); - CAmount effectiveAmount = 0; - bool claim_found = false; - for (std::vector::iterator it=claims.claims.begin(); it!=claims.claims.end(); ++it) - { - if (it->claimId == claimId && it->nValidAtHeight < nCurrentHeight) - { - effectiveAmount += it->nAmount; - claim_found = true; - break; - } - } - if (!claim_found) - return effectiveAmount; + std::vector supports; + return getEffectiveAmountForClaimWithSupports(name, claimId, supports); +} - for (std::vector::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it) - { - if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight) - effectiveAmount += it->nAmount; - } - return effectiveAmount; +//return effective amount from claim and the supports used as inputs, retuns 0 if claim is not found +CAmount CClaimTrie::getEffectiveAmountForClaimWithSupports(const std::string& name, uint160 claimId, + std::vector& supports) const +{ + claimsForNameType claims = getClaimsForName(name); + CAmount effectiveAmount = 0; + bool claim_found = false; + for (std::vector::iterator it=claims.claims.begin(); it!=claims.claims.end(); ++it) + { + if (it->claimId == claimId && it->nValidAtHeight < nCurrentHeight) + { + effectiveAmount += it->nAmount; + claim_found = true; + break; + } + } + if (!claim_found) + return effectiveAmount; + for (std::vector::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it) + { + if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight) + { + effectiveAmount += it->nAmount; + supports.push_back(*it); + } + } + return effectiveAmount; } bool CClaimTrie::checkConsistency() const diff --git a/src/claimtrie.h b/src/claimtrie.h index b3ec6e6c0..b7311a87a 100644 --- a/src/claimtrie.h +++ b/src/claimtrie.h @@ -321,6 +321,8 @@ public: claimsForNameType getClaimsForName(const std::string& name) const; CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const; + CAmount getEffectiveAmountForClaimWithSupports(const std::string& name, uint160 claimId, + std::vector& supports) const; bool queueEmpty() const; bool supportEmpty() const; diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index e6f0fc5eb..db9a261fe 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -367,6 +367,14 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp) " \"amount\" (numeric) txout value\n" " \"effective amount\" (numeric) txout amount plus amount from all supports associated with the claim\n" " \"height\" (numeric) the height of the block in which this claim transaction is located\n" + " \"supports\" (array of object) supports for this claim\n" + " [\n" + " \"txid\" (string) the txid of the support\n" + " \"n\" (numeric) the index of the support in the transaction's list of outputs\n" + " \"height\" (numeric) the height at which the support was included in the blockchain\n" + " \"valid at height\" (numeric) the height at which the support became/becomes valid\n" + " \"amount\" (numeric) the amount of the support\n" + " ]\n" "}\n" ); @@ -379,6 +387,10 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp) pclaimTrie->getClaimById(claimId, name, claimValue); if (claimValue.claimId == claimId) { + std::vector supports; + CAmount effectiveAmount = pclaimTrie->getEffectiveAmountForClaimWithSupports( + name, claimValue.claimId, supports); + std::string sValue; getValueForClaim(claimValue.outPoint, sValue); claim.push_back(Pair("name", name)); @@ -387,9 +399,20 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp) claim.push_back(Pair("txid", claimValue.outPoint.hash.GetHex())); claim.push_back(Pair("n", (int) claimValue.outPoint.n)); claim.push_back(Pair("amount", claimValue.nAmount)); - claim.push_back(Pair("effective amount", - pclaimTrie->getEffectiveAmountForClaim(name, claimValue.claimId))); + claim.push_back(Pair("effective amount", effectiveAmount)); + UniValue supportList(UniValue::VARR); + BOOST_FOREACH(const CSupportValue& support, supports) { + UniValue supportEntry(UniValue::VOBJ); + supportEntry.push_back(Pair("txid", support.outPoint.hash.GetHex())); + supportEntry.push_back(Pair("n", (int)support.outPoint.n)); + supportEntry.push_back(Pair("height", support.nHeight)); + supportEntry.push_back(Pair("valid at height", support.nValidAtHeight)); + supportEntry.push_back(Pair("amount", support.nAmount)); + supportList.push_back(supportEntry); + } + claim.push_back(Pair("supports", supportList)); claim.push_back(Pair("height", claimValue.nHeight)); + claim.push_back(Pair("valid at height", claimValue.nValidAtHeight)); } return claim; }