Add support information to getclaimbyid rpc #142
3 changed files with 59 additions and 23 deletions
|
@ -526,31 +526,41 @@ claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const
|
||||||
return allClaims;
|
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
|
CAmount CClaimTrie::getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const
|
||||||
{
|
{
|
||||||
claimsForNameType claims = getClaimsForName(name);
|
std::vector<CSupportValue> supports;
|
||||||
CAmount effectiveAmount = 0;
|
return getEffectiveAmountForClaimWithSupports(name, claimId, supports);
|
||||||
bool claim_found = false;
|
}
|
||||||
for (std::vector<CClaimValue>::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<CSupportValue>::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it)
|
//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,
|
||||||
if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight)
|
std::vector<CSupportValue>& supports) const
|
||||||
effectiveAmount += it->nAmount;
|
{
|
||||||
}
|
claimsForNameType claims = getClaimsForName(name);
|
||||||
return effectiveAmount;
|
CAmount effectiveAmount = 0;
|
||||||
|
bool claim_found = false;
|
||||||
|
for (std::vector<CClaimValue>::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<CSupportValue>::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
|
bool CClaimTrie::checkConsistency() const
|
||||||
|
|
|
@ -321,6 +321,8 @@ public:
|
||||||
|
|
||||||
claimsForNameType getClaimsForName(const std::string& name) const;
|
claimsForNameType getClaimsForName(const std::string& name) const;
|
||||||
CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const;
|
CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const;
|
||||||
|
CAmount getEffectiveAmountForClaimWithSupports(const std::string& name, uint160 claimId,
|
||||||
|
std::vector<CSupportValue>& supports) const;
|
||||||
|
|
||||||
bool queueEmpty() const;
|
bool queueEmpty() const;
|
||||||
bool supportEmpty() const;
|
bool supportEmpty() const;
|
||||||
|
|
|
@ -367,6 +367,15 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
|
||||||
" \"amount\" (numeric) txout value\n"
|
" \"amount\" (numeric) txout value\n"
|
||||||
" \"effective amount\" (numeric) txout amount plus amount from all supports associated with the claim\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"
|
" \"height\" (numeric) the height of the block in which this claim transaction is located\n"
|
||||||
|
" \"supports\" (array of object) supports for this claim\n"
|
||||||
|
" \"valid at height\" (numeric) the height at which the claim is valid\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 is valid\n"
|
||||||
|
" \"amount\" (numeric) the amount of the support\n"
|
||||||
|
" ]\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -379,6 +388,10 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
|
||||||
pclaimTrie->getClaimById(claimId, name, claimValue);
|
pclaimTrie->getClaimById(claimId, name, claimValue);
|
||||||
if (claimValue.claimId == claimId)
|
if (claimValue.claimId == claimId)
|
||||||
{
|
{
|
||||||
|
std::vector<CSupportValue> supports;
|
||||||
|
CAmount effectiveAmount = pclaimTrie->getEffectiveAmountForClaimWithSupports(
|
||||||
|
name, claimValue.claimId, supports);
|
||||||
|
|
||||||
std::string sValue;
|
std::string sValue;
|
||||||
getValueForClaim(claimValue.outPoint, sValue);
|
getValueForClaim(claimValue.outPoint, sValue);
|
||||||
claim.push_back(Pair("name", name));
|
claim.push_back(Pair("name", name));
|
||||||
|
@ -387,9 +400,20 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
|
||||||
claim.push_back(Pair("txid", claimValue.outPoint.hash.GetHex()));
|
claim.push_back(Pair("txid", claimValue.outPoint.hash.GetHex()));
|
||||||
claim.push_back(Pair("n", (int) claimValue.outPoint.n));
|
claim.push_back(Pair("n", (int) claimValue.outPoint.n));
|
||||||
claim.push_back(Pair("amount", claimValue.nAmount));
|
claim.push_back(Pair("amount", claimValue.nAmount));
|
||||||
claim.push_back(Pair("effective amount",
|
claim.push_back(Pair("effective amount", effectiveAmount));
|
||||||
pclaimTrie->getEffectiveAmountForClaim(name, claimValue.claimId)));
|
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("height", claimValue.nHeight));
|
||||||
|
claim.push_back(Pair("valid at height", claimValue.nValidAtHeight));
|
||||||
}
|
}
|
||||||
return claim;
|
return claim;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue
good catch