fixed some RPC tests
This commit is contained in:
parent
6b22f66325
commit
5f8b0b6f55
4 changed files with 24 additions and 19 deletions
|
@ -341,21 +341,26 @@ bool CClaimTrieCacheBase::getInfoForName(const std::string& name, CClaimValue& c
|
|||
CClaimSupportToName CClaimTrieCacheBase::getClaimsForName(const std::string& name) const
|
||||
{
|
||||
int nLastTakeoverHeight = 0;
|
||||
db << "SELECT IFNULL(takeoverHeight,0) FROM nodes WHERE name = ?" << name >> nLastTakeoverHeight;
|
||||
|
||||
{
|
||||
auto query = db << "SELECT takeoverHeight FROM nodes WHERE name = ?" << name;
|
||||
auto it = query.begin();
|
||||
if (it != query.end())
|
||||
*it >> nLastTakeoverHeight;
|
||||
}
|
||||
auto supports = getSupportsForName(name);
|
||||
|
||||
auto query = db << "SELECT claimID, txID, txN, blockHeight, validHeight, amount "
|
||||
"FROM claims WHERE nodeName = ? AND expirationHeight >= ?"
|
||||
<< name << nNextHeight;
|
||||
claimEntryType claims;
|
||||
for (auto&& row: query) {
|
||||
CClaimValue claim;
|
||||
row >> claim.claimId >> claim.outPoint.hash >> claim.outPoint.n
|
||||
>> claim.nHeight >> claim.nValidAtHeight >> claim.nAmount;
|
||||
claims.push_back(claim);
|
||||
{
|
||||
auto query = db << "SELECT claimID, txID, txN, blockHeight, validHeight, amount "
|
||||
"FROM claims WHERE nodeName = ? AND expirationHeight >= ?"
|
||||
<< name << nNextHeight;
|
||||
for (auto &&row: query) {
|
||||
CClaimValue claim;
|
||||
row >> claim.claimId >> claim.outPoint.hash >> claim.outPoint.n
|
||||
>> claim.nHeight >> claim.nValidAtHeight >> claim.nAmount;
|
||||
claims.push_back(claim);
|
||||
}
|
||||
}
|
||||
|
||||
auto find = [&supports](decltype(supports)::iterator& it, const CClaimValue& claim) {
|
||||
it = std::find_if(it, supports.end(), [&claim](const CSupportValue& support) {
|
||||
return claim.claimId == support.supportedClaimId;
|
||||
|
@ -375,7 +380,7 @@ CClaimSupportToName CClaimTrieCacheBase::getClaimsForName(const std::string& nam
|
|||
}
|
||||
ic->claim.nEffectiveAmount = ic->effectiveAmount;
|
||||
}
|
||||
std::sort(claimsNsupports.begin(), claimsNsupports.end());
|
||||
std::sort(claimsNsupports.rbegin(), claimsNsupports.rend());
|
||||
return {name, nLastTakeoverHeight, std::move(claimsNsupports), std::move(supports)};
|
||||
}
|
||||
|
||||
|
@ -1303,10 +1308,11 @@ bool CClaimTrieCacheBase::getProofForName(const std::string& name, const uint160
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheBase::findNameForClaim(const std::vector<unsigned char>& claim, CClaimValue& value, std::string& name) {
|
||||
bool CClaimTrieCacheBase::findNameForClaim(std::vector<unsigned char> claim, CClaimValue& value, std::string& name) {
|
||||
std::reverse(claim.begin(), claim.end());
|
||||
auto query = db << "SELECT nodeName, claimId, txID, txN, amount, validHeight, blockHeight "
|
||||
"FROM claims WHERE SUBSTR(claimID, 1, ?) = ? AND validHeight < ? AND expirationHeight >= ?"
|
||||
<< claim.size() << claim << nNextHeight << nNextHeight;
|
||||
"FROM claims WHERE SUBSTR(claimID, ?) = ? AND validHeight < ? AND expirationHeight >= ?"
|
||||
<< -claim.size() << claim << nNextHeight << nNextHeight;
|
||||
auto hit = false;
|
||||
for (auto&& row: query) {
|
||||
if (hit) return false;
|
||||
|
|
|
@ -374,7 +374,7 @@ public:
|
|||
std::size_t getTotalClaimsInTrie() const;
|
||||
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
|
||||
|
||||
bool findNameForClaim(const std::vector<unsigned char>& claim, CClaimValue& value, std::string& name);
|
||||
bool findNameForClaim(std::vector<unsigned char> claim, CClaimValue& value, std::string& name);
|
||||
void getNamesInTrie(std::function<void(const std::string&)> callback);
|
||||
bool getLastTakeoverForName(const std::string& name, uint160& claimId, int& takeoverHeight) const;
|
||||
|
||||
|
|
|
@ -464,8 +464,7 @@ UniValue getclaimbyid(const JSONRPCRequest& request)
|
|||
std::string foundName;
|
||||
CClaimValue foundClaim;
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
auto parsed = ParseHex(claimId);
|
||||
if (trieCache.findNameForClaim(parsed, foundClaim, foundName)) {
|
||||
if (trieCache.findNameForClaim(ParseHex(claimId), foundClaim, foundName)) {
|
||||
auto csToName = trieCache.getClaimsForName(foundName);
|
||||
auto& claimNsupports = csToName.find(foundClaim.claimId);
|
||||
if (!claimNsupports.IsNull()) {
|
||||
|
|
|
@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(hash_bid_seq_claim_changes_test)
|
|||
req.params.push_back(UniValue(blockhash.GetHex()));
|
||||
|
||||
result = getchangesinblock(req);
|
||||
BOOST_CHECK_EQUAL(result[T_CLAIMSADDEDORUPDATED].size(), 3);
|
||||
BOOST_REQUIRE_EQUAL(result[T_CLAIMSADDEDORUPDATED].size(), 3);
|
||||
BOOST_CHECK_EQUAL(result[T_CLAIMSADDEDORUPDATED][0].get_str(), claimId2.GetHex());
|
||||
BOOST_CHECK_EQUAL(result[T_CLAIMSADDEDORUPDATED][1].get_str(), claimId3.GetHex());
|
||||
BOOST_CHECK_EQUAL(result[T_CLAIMSADDEDORUPDATED][2].get_str(), claimId4.GetHex());
|
||||
|
|
Loading…
Reference in a new issue