Add pending effective amount to rpc methods #232

Closed
bvbfan wants to merge 313 commits from pending_affective_amount into master
2 changed files with 48 additions and 0 deletions
Showing only changes of commit 785ca8aeec - Show all commits

View file

@ -236,6 +236,7 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
"\"n\" (numeric) vout value\n"
"\"amount\" (numeric) txout amount\n"
"\"effective amount\" (numeric) txout amount plus amount from all supports associated with the claim\n"
"\"pending effective amount\" (numeric) expected effective amount when claim and its support got valid\n"
"\"height\" (numeric) the height of the block in which this transaction is located\n");
LOCK(cs_main);
@ -267,6 +268,10 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
ret.push_back(Pair("n", (int)claim.outPoint.n));
ret.push_back(Pair("amount", claim.nAmount));
ret.push_back(Pair("effective amount", nEffectiveAmount));
if (nEffectiveAmount < claim.nEffectiveAmount)
ret.push_back(Pair("pending effective amount", claim.nEffectiveAmount));
ret.push_back(Pair("height", claim.nHeight));
return ret;
}
@ -301,6 +306,10 @@ UniValue claimAndSupportsToJSON(CAmount nEffectiveAmount, claimSupportMapType::c
ret.push_back(Pair("nValidAtHeight", claim.nValidAtHeight));
ret.push_back(Pair("nAmount", claim.nAmount));
ret.push_back(Pair("nEffectiveAmount", nEffectiveAmount));
if (nEffectiveAmount < claim.nEffectiveAmount)
ret.push_back(Pair("nPendingEffectiveAmount", claim.nEffectiveAmount));
ret.push_back(Pair("supports", supportObjs));
return ret;
}
@ -331,6 +340,7 @@ UniValue getclaimsforname(const UniValue& params, bool fHelp)
" \"nValidAtHeight\" (numeric) the height at which the claim became/becomes valid\n"
" \"nAmount\" (numeric) the amount of the claim\n"
" \"nEffectiveAmount\" (numeric) the total effective amount of the claim, taking into effect whether the claim or support has reached its nValidAtHeight\n"
" \"nPendingEffectiveAmount\" (numeric) expected effective amount when claim and its support got valid\n"
" \"supports\" : [ (array of object) supports for this claim\n"
" \"txid\" (string) the txid of the support\n"
" \"n\" (numeric) the index of the support in the transaction's list of outputs\n"
@ -414,6 +424,7 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
" \"n\" (numeric) vout value\n"
" \"amount\" (numeric) txout value\n"
" \"effective amount\" (numeric) txout amount plus amount from all supports associated with the claim\n"
" \"pending effective amount\" (numeric) expected effective amount when claim and its support got valid\n"
" \"supports\" (array of object) supports for this claim\n"
" [\n"
" \"txid\" (string) the txid of the support\n"
@ -447,6 +458,10 @@ UniValue getclaimbyid(const UniValue& params, bool fHelp)
claim.push_back(Pair("n", (int) claimValue.outPoint.n));
claim.push_back(Pair("amount", claimValue.nAmount));
claim.push_back(Pair("effective amount", effectiveAmount));
if (effectiveAmount < claimValue.nEffectiveAmount)
claim.push_back(Pair("pending effective amount", claimValue.nEffectiveAmount));
UniValue supportList(UniValue::VARR);
BOOST_FOREACH(const CSupportValue& support, supports) {
UniValue supportEntry(UniValue::VOBJ);

View file

@ -3378,4 +3378,37 @@ BOOST_AUTO_TEST_CASE(claim_rpcs_rollback3_test)
BOOST_CHECK(valueResults["amount"].get_int() == 3);
}
BOOST_AUTO_TEST_CASE(claim_rpcs_pending_effective_amount_test)
{
ClaimTrieChainFixture fixture;
std::string sName1("test");
std::string sValue1("test1");
std::string sValue2("test2");
rpcfn_type getclaimsforname = tableRPC["getclaimsforname"]->actor;
UniValue claims;
UniValue params(UniValue::VARR);
params.push_back(UniValue(sName1));
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(), sName1, sValue1, 1);
fixture.IncrementBlocks(1);
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(), sName1, sValue2, 2);
fixture.IncrementBlocks(1);
claims = getclaimsforname(params, false)["claims"];
BOOST_CHECK(claims.size() == 2U);
BOOST_CHECK(claims[0]["nEffectiveAmount"].get_int() == 0);
BOOST_CHECK(claims[0].exists("nPendingEffectiveAmount"));
BOOST_CHECK(claims[0]["nPendingEffectiveAmount"].get_int() == 2);
fixture.IncrementBlocks(1);
claims = getclaimsforname(params, false)["claims"];
BOOST_CHECK(claims.size() == 2U);
BOOST_CHECK(claims[0]["nEffectiveAmount"].get_int() == 2);
BOOST_CHECK(!claims[0].exists("nPendingEffectiveAmount"));
}
BOOST_AUTO_TEST_SUITE_END()