Adding effective amount function to CClaimTrie #55
4 changed files with 50 additions and 14 deletions
|
@ -525,6 +525,31 @@ claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const
|
||||||
return allClaims;
|
return allClaims;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//return effective amount form 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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool CClaimTrie::checkConsistency() const
|
bool CClaimTrie::checkConsistency() const
|
||||||
{
|
{
|
||||||
if (empty())
|
if (empty())
|
||||||
|
|
|
@ -302,7 +302,8 @@ public:
|
||||||
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
||||||
|
|
||||||
claimsForNameType getClaimsForName(const std::string& name) const;
|
claimsForNameType getClaimsForName(const std::string& name) const;
|
||||||
|
CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const;
|
||||||
|
|
||||||
bool queueEmpty() const;
|
bool queueEmpty() const;
|
||||||
bool supportEmpty() const;
|
bool supportEmpty() const;
|
||||||
bool supportQueueEmpty() const;
|
bool supportQueueEmpty() const;
|
||||||
|
|
|
@ -187,7 +187,7 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
|
||||||
ret.push_back(Pair("txid", claim.outPoint.hash.GetHex()));
|
ret.push_back(Pair("txid", claim.outPoint.hash.GetHex()));
|
||||||
ret.push_back(Pair("n", (int)claim.outPoint.n));
|
ret.push_back(Pair("n", (int)claim.outPoint.n));
|
||||||
ret.push_back(Pair("amount", claim.nAmount));
|
ret.push_back(Pair("amount", claim.nAmount));
|
||||||
ret.push_back(Pair("effective amount", claim.nEffectiveAmount));
|
ret.push_back(Pair("effective amount", pclaimTrie->getEffectiveAmountForClaim(name, claim.claimId)));
|
||||||
ret.push_back(Pair("height", claim.nHeight));
|
ret.push_back(Pair("height", claim.nHeight));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,18 +68,22 @@ best_claim_effective_amount_equals(std::string name, CAmount amount)
|
||||||
if (!have_info)
|
if (!have_info)
|
||||||
{
|
{
|
||||||
boost::test_tools::predicate_result res(false);
|
boost::test_tools::predicate_result res(false);
|
||||||
res.message()<<"No claim found";
|
res.message()<<"No claim found";
|
||||||
return res;
|
return res;
|
||||||
}
|
|
||||||
else if (val.nEffectiveAmount != amount)
|
|
||||||
{
|
|
||||||
boost::test_tools::predicate_result res(false);
|
|
||||||
res.message()<<amount<<" != "<<val.nEffectiveAmount;
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return true;
|
CAmount effective_amount = pclaimTrie->getEffectiveAmountForClaim(name, val.claimId);
|
||||||
|
if (val.nEffectiveAmount != amount)
|
||||||
|
{
|
||||||
|
boost::test_tools::predicate_result res(false);
|
||||||
|
res.message()<<amount<<" != "<<effective_amount;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -442,24 +446,30 @@ BOOST_AUTO_TEST_CASE(claimtriebranching_support)
|
||||||
CMutableTransaction s2 = fixture.MakeSupport(fixture.GetCoinbase(),tx2,"test",10);
|
CMutableTransaction s2 = fixture.MakeSupport(fixture.GetCoinbase(),tx2,"test",10);
|
||||||
fixture.IncrementBlocks(1);
|
fixture.IncrementBlocks(1);
|
||||||
BOOST_CHECK(is_best_claim("test",tx2));
|
BOOST_CHECK(is_best_claim("test",tx2));
|
||||||
fixture.DecrementBlocks(1);
|
BOOST_CHECK(best_claim_effective_amount_equals("test",11));
|
||||||
|
fixture.DecrementBlocks(1);
|
||||||
|
|
||||||
// check support delay
|
// check support delay
|
||||||
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
|
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
|
||||||
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","two",2);
|
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","two",2);
|
||||||
fixture.IncrementBlocks(10);
|
fixture.IncrementBlocks(10);
|
||||||
BOOST_CHECK(is_best_claim("test",tx4));
|
BOOST_CHECK(is_best_claim("test",tx4));
|
||||||
|
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
|
||||||
CMutableTransaction s4 = fixture.MakeSupport(fixture.GetCoinbase(),tx3,"test",10); //10 delay
|
CMutableTransaction s4 = fixture.MakeSupport(fixture.GetCoinbase(),tx3,"test",10); //10 delay
|
||||||
fixture.IncrementBlocks(10);
|
fixture.IncrementBlocks(10);
|
||||||
BOOST_CHECK(is_best_claim("test",tx4));
|
BOOST_CHECK(is_best_claim("test",tx4));
|
||||||
|
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
|
||||||
fixture.IncrementBlocks(1);
|
fixture.IncrementBlocks(1);
|
||||||
BOOST_CHECK(is_best_claim("test",tx3));
|
BOOST_CHECK(is_best_claim("test",tx3));
|
||||||
|
BOOST_CHECK(best_claim_effective_amount_equals("test",11));
|
||||||
|
|
||||||
fixture.DecrementBlocks(1);
|
fixture.DecrementBlocks(1);
|
||||||
BOOST_CHECK(is_best_claim("test",tx4));
|
BOOST_CHECK(is_best_claim("test",tx4));
|
||||||
|
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
|
||||||
fixture.DecrementBlocks(10);
|
fixture.DecrementBlocks(10);
|
||||||
BOOST_CHECK(is_best_claim("test",tx4));
|
BOOST_CHECK(is_best_claim("test",tx4));
|
||||||
fixture.DecrementBlocks(10);
|
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
|
||||||
|
fixture.DecrementBlocks(10);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
support spend
|
support spend
|
||||||
|
|
Loading…
Reference in a new issue