Add support information to getclaimbyid rpc
This commit is contained in:
parent
df4a86a0df
commit
756c13c188
3 changed files with 58 additions and 23 deletions
|
@ -526,8 +526,16 @@ 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
|
||||||
|
{
|
||||||
|
std::vector<CSupportValue> supports;
|
||||||
|
return getEffectiveAmountForClaimWithSupports(name, claimId, supports);
|
||||||
|
}
|
||||||
|
|
||||||
|
//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<CSupportValue>& supports) const
|
||||||
{
|
{
|
||||||
claimsForNameType claims = getClaimsForName(name);
|
claimsForNameType claims = getClaimsForName(name);
|
||||||
CAmount effectiveAmount = 0;
|
CAmount effectiveAmount = 0;
|
||||||
|
@ -547,10 +555,12 @@ CAmount CClaimTrie::getEffectiveAmountForClaim(const std::string& name, uint160
|
||||||
for (std::vector<CSupportValue>::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it)
|
for (std::vector<CSupportValue>::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight)
|
if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight)
|
||||||
|
{
|
||||||
effectiveAmount += it->nAmount;
|
effectiveAmount += it->nAmount;
|
||||||
|
supports.push_back(*it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return effectiveAmount;
|
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,14 @@ 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"
|
||||||
|
" [\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"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -379,6 +387,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 +399,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