diff --git a/src/claimtrie/forks.cpp b/src/claimtrie/forks.cpp index 50a32c365..86b3a6524 100644 --- a/src/claimtrie/forks.cpp +++ b/src/claimtrie/forks.cpp @@ -417,4 +417,4 @@ bool CClaimTrieCacheHashFork::finalizeDecrement() bool CClaimTrieCacheHashFork::allowSupportMetadata() const { return nNextHeight >= base->nAllClaimsInMerkleForkHeight; -} +} \ No newline at end of file diff --git a/src/claimtrie/trie.cpp b/src/claimtrie/trie.cpp index 5576fcbc7..e3fff6602 100644 --- a/src/claimtrie/trie.cpp +++ b/src/claimtrie/trie.cpp @@ -888,3 +888,40 @@ void CClaimTrieCacheBase::getNamesInTrie(std::function callback(name); }; } + +std::vector CClaimTrieCacheBase::getActivatedClaims(int height) { + std::vector ret; + auto query = db << "SELECT DISTINCT claimID FROM claim WHERE activationHeight = ?1 AND blockHeight < ?1" << height; + for (auto&& row: query) { + ret.emplace_back(); + row >> ret.back(); + } + return ret; +} +std::vector CClaimTrieCacheBase::getClaimsWithActivatedSupports(int height) { + std::vector ret; + auto query = db << "SELECT DISTINCT supportedClaimID FROM support WHERE activationHeight = ?1 AND blockHeight < ?1" << height; + for (auto&& row: query) { + ret.emplace_back(); + row >> ret.back(); + } + return ret; +} +std::vector CClaimTrieCacheBase::getExpiredClaims(int height) { + std::vector ret; + auto query = db << "SELECT DISTINCT claimID FROM claim WHERE expirationHeight = ?1 AND blockHeight < ?1" << height; + for (auto&& row: query) { + ret.emplace_back(); + row >> ret.back(); + } + return ret; +} +std::vector CClaimTrieCacheBase::getClaimsWithExpiredSupports(int height) { + std::vector ret; + auto query = db << "SELECT DISTINCT supportedClaimID FROM support WHERE expirationHeight = ?1 AND blockHeight < ?1" << height; + for (auto&& row: query) { + ret.emplace_back(); + row >> ret.back(); + } + return ret; +} \ No newline at end of file diff --git a/src/claimtrie/trie.h b/src/claimtrie/trie.h index cf4281157..e5ff1bb15 100644 --- a/src/claimtrie/trie.h +++ b/src/claimtrie/trie.h @@ -102,6 +102,11 @@ public: bool getLastTakeoverForName(const std::string& name, CUint160& claimId, int& takeoverHeight) const; bool findNameForClaim(std::vector claim, CClaimValue& value, std::string& name) const; + std::vector getActivatedClaims(int height); + std::vector getClaimsWithActivatedSupports(int height); + std::vector getExpiredClaims(int height); + std::vector getClaimsWithExpiredSupports(int height); + protected: int nNextHeight; // Height of the block that is being worked on, which is CClaimTrie* base; diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index 7c6afddc8..7edfe0fa7 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -751,22 +751,34 @@ UniValue getchangesinblock(const JSONRPCRequest& request) LOCK(cs_main); bool allowSupportMetadata; CCoinsViewCache coinsCache(pcoinsTip.get()); + + UniValue claimsAddUp(UniValue::VARR), + claimsRm(UniValue::VARR), + supportsAddUp(UniValue::VARR), + supportsRm(UniValue::VARR); + { auto index = chainActive.Tip(); if (request.params.size() > 0) index = BlockHashIndex(ParseHashV(request.params[0], T_BLOCKHASH " (optional parameter)")); + CClaimTrieCache trieCache(pclaimTrie); + RollBackTo(index, coinsCache, trieCache); if (!ReadBlockFromDisk(block, index, Params().GetConsensus())) throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read the undo block for height " + std::to_string(index->nHeight)); allowSupportMetadata = index->nHeight >= Params().GetConsensus().nAllClaimsInMerkleForkHeight; - } - UniValue claimsAddUp(UniValue::VARR), - claimsRm(UniValue::VARR), - supportsAddUp(UniValue::VARR), - supportsRm(UniValue::VARR); + for (auto& claim: trieCache.getActivatedClaims(index->nHeight)) + claimsAddUp.push_back(claim.ToString()); + for (auto& claim: trieCache.getClaimsWithActivatedSupports(index->nHeight)) + supportsAddUp.push_back(claim.ToString()); + for (auto& claim: trieCache.getExpiredClaims(index->nHeight)) + claimsRm.push_back(claim.ToString()); + for (auto& claim: trieCache.getClaimsWithExpiredSupports(index->nHeight)) + supportsRm.push_back(claim.ToString()); + } int op; std::vector > vvchParams; @@ -802,6 +814,7 @@ UniValue getchangesinblock(const JSONRPCRequest& request) break; case OP_SUPPORT_CLAIM: supportsRm.push_back(uint160(vvchParams[1]).ToString()); + break; } } @@ -815,11 +828,14 @@ UniValue getchangesinblock(const JSONRPCRequest& request) switch (op) { case OP_CLAIM_NAME: - case OP_UPDATE_CLAIM: claimsAddUp.push_back(ClaimIdHash(tx->GetHash(), i).ToString()); break; + case OP_UPDATE_CLAIM: + claimsAddUp.push_back(uint160(vvchParams[1]).ToString()); + break; case OP_SUPPORT_CLAIM: - supportsAddUp.push_back(ClaimIdHash(tx->GetHash(), i).ToString()); + supportsAddUp.push_back(uint160(vvchParams[1]).ToString()); + break; } } } diff --git a/src/test/claimtrierpc_tests.cpp b/src/test/claimtrierpc_tests.cpp index 268436ce4..67a5d67c2 100644 --- a/src/test/claimtrierpc_tests.cpp +++ b/src/test/claimtrierpc_tests.cpp @@ -360,8 +360,10 @@ 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(), 1); - BOOST_CHECK_EQUAL(result[T_CLAIMSADDEDORUPDATED][0].get_str(), claimId4.GetHex()); + BOOST_CHECK_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()); BOOST_CHECK_EQUAL(result[T_CLAIMSREMOVED].size(), 0); BOOST_CHECK_EQUAL(result[T_SUPPORTSADDEDORUPDATED].size(), 0); BOOST_CHECK_EQUAL(result[T_SUPPORTSREMOVED].size(), 0);