hacktober fest #214
3 changed files with 58 additions and 23 deletions
|
@ -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<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;
|
||||
std::vector<CSupportValue> supports;
|
||||
return getEffectiveAmountForClaimWithSupports(name, claimId, supports);
|
||||
}
|
||||
|
||||
for (std::vector<CSupportValue>::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<CSupportValue>& supports) const
|
||||
{
|
||||
claimsForNameType claims = getClaimsForName(name);
|
||||
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
|
||||
|
|
|
@ -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<CSupportValue>& supports) const;
|
||||
|
||||
bool queueEmpty() const;
|
||||
bool supportEmpty() const;
|
||||
|
|
|
@ -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<CSupportValue> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue