diff --git a/src/claimtrie.cpp b/src/claimtrie.cpp index 1473ef59c..5bc04348a 100644 --- a/src/claimtrie.cpp +++ b/src/claimtrie.cpp @@ -458,6 +458,73 @@ bool CClaimTrie::getLastTakeoverForName(const std::string& name, int& lastTakeov return false; } +claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const +{ + std::vector claims; + std::vector supports; + int nLastTakeoverHeight = 0; + const CClaimTrieNode* current = getNodeForName(name); + if (current) + { + if (!current->claims.empty()) + { + nLastTakeoverHeight = current->nHeightOfLastTakeover; + } + for (std::vector::const_iterator itClaims = current->claims.begin(); itClaims != current->claims.end(); ++itClaims) + { + claims.push_back(*itClaims); + } + } + supportMapEntryType supportNode; + if (getSupportNode(name, supportNode)) + { + for (std::vector::const_iterator itSupports = supportNode.begin(); itSupports != supportNode.end(); ++itSupports) + { + supports.push_back(*itSupports); + } + } + queueNameRowType namedClaimRow; + if (getQueueNameRow(name, namedClaimRow)) + { + for (queueNameRowType::const_iterator itClaimsForName = namedClaimRow.begin(); itClaimsForName != namedClaimRow.end(); ++itClaimsForName) + { + claimQueueRowType claimRow; + if (getQueueRow(itClaimsForName->nHeight, claimRow)) + { + for (claimQueueRowType::const_iterator itClaimRow = claimRow.begin(); itClaimRow != claimRow.end(); ++itClaimRow) + { + if (itClaimRow->first == name && itClaimRow->second.outPoint == itClaimsForName->outPoint) + { + claims.push_back(itClaimRow->second); + break; + } + } + } + } + } + queueNameRowType namedSupportRow; + if (getSupportQueueNameRow(name, namedSupportRow)) + { + for (queueNameRowType::const_iterator itSupportsForName = namedSupportRow.begin(); itSupportsForName != namedSupportRow.end(); ++itSupportsForName) + { + supportQueueRowType supportRow; + if (getSupportQueueRow(itSupportsForName->nHeight, supportRow)) + { + for (supportQueueRowType::const_iterator itSupportRow = supportRow.begin(); itSupportRow != supportRow.end(); ++itSupportRow) + { + if (itSupportRow->first == name && itSupportRow->second.outPoint == itSupportsForName->outPoint) + { + supports.push_back(itSupportRow->second); + break; + } + } + } + } + } + claimsForNameType allClaims(claims, supports, nLastTakeoverHeight); + return allClaims; +} + bool CClaimTrie::checkConsistency() const { if (empty()) diff --git a/src/claimtrie.h b/src/claimtrie.h index 6cd28b7b2..6d6396ba7 100644 --- a/src/claimtrie.h +++ b/src/claimtrie.h @@ -265,6 +265,16 @@ typedef std::map nodeCacheType; typedef std::map hashMapType; +struct claimsForNameType +{ + std::vector claims; + std::vector supports; + int nLastTakeoverHeight; + + claimsForNameType(std::vector claims, std::vector supports, int nLastTakeoverHeight) + : claims(claims), supports(supports), nLastTakeoverHeight(nLastTakeoverHeight) {} +}; + class CClaimTrieCache; class CClaimTrie @@ -290,6 +300,8 @@ public: std::vector flattenTrie() const; bool getInfoForName(const std::string& name, CClaimValue& claim) const; bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const; + + claimsForNameType getClaimsForName(const std::string& name) const; bool queueEmpty() const; bool supportEmpty() const; diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index 38c178127..da2289ba9 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -181,6 +181,34 @@ UniValue getvalueforname(const UniValue& params, bool fHelp) return ret; } +UniValue getclaimsforname(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw std::runtime_error( + "getclaimsforname\n" + "Return a whole bunch of stuff, I tell you what" + ); + + LOCK(cs_main); + std::string name = params[0].get_str(); + claimsForNameType claimsForName = pclaimTrie->getClaimsForName(name); + UniValue ret(UniValue::VARR); + for (std::vector::const_iterator itClaims = claimsForName.claims.begin(); itClaims != claimsForName.claims.end(); ++itClaims) + { + UniValue claim(UniValue::VOBJ); + claim.push_back(Pair("txid", itClaims->outPoint.hash.GetHex())); + ret.push_back(claim); + } + for (std::vector::const_iterator itSupports = claimsForName.supports.begin(); itSupports != claimsForName.supports.end(); ++itSupports) + { + UniValue support(UniValue::VOBJ); + support.push_back(Pair("txid", itSupports->outPoint.hash.GetHex())); + ret.push_back(support); + } + return ret; +} + + UniValue gettotalclaimednames(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -535,6 +563,7 @@ static const CRPCCommand commands[] = { "Claimtrie", "getclaimsintrie", &getclaimsintrie, true }, { "Claimtrie", "getclaimtrie", &getclaimtrie, true }, { "Claimtrie", "getvalueforname", &getvalueforname, true }, + { "Claimtrie", "getclaimsforname", &getclaimsforname, true }, { "Claimtrie", "gettotalclaimednames", &gettotalclaimednames, true }, { "Claimtrie", "gettotalclaims", &gettotalclaims, true }, { "Claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },