diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index 26b71547a..c15020087 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -349,6 +349,53 @@ UniValue getclaimsforname(const UniValue& params, bool fHelp) return ret; } +UniValue getclaimbyid(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw std::runtime_error( + "getclaimbyid\n" + "Get a claim by claim id\n" + "Arguments: \n" + "1. \"claimId\" (string) the claimId of this claim\n" + "Result:\n" + "{\n" + " \"name\" (string) the name of the claim\n" + " \"claimId\" (string) the claimId of this claim\n" + " \"txid\" (string) the hash of the transaction which has successfully claimed this name\n" + " \"n\" (numeric) vout value\n" + " \"amount\" (numeric) txout value\n" + " \"height\" (numeric) the height of the block in which this claim transaction is located\n" + " \"value\" (string) claim metadata\n" + "}\n" + ); + + LOCK(cs_main); + uint160 claimId; + claimId.SetHex(params[0].get_str()); + + std::vector nodes = pclaimTrie->flattenTrie(); + for (std::vector::iterator it = nodes.begin(); it != nodes.end(); ++it) { + if (!it->second.claims.empty()) { + for (std::vector::iterator itClaims = it->second.claims.begin(); + itClaims != it->second.claims.end(); ++itClaims) { + if (claimId == itClaims->claimId) { + UniValue claim(UniValue::VOBJ); + std::string sValue; + getValueForClaim(itClaims->outPoint, sValue); + claim.push_back(Pair("name", it->first)); + claim.push_back(Pair("claimId", itClaims->claimId.GetHex())); + claim.push_back(Pair("txid", itClaims->outPoint.hash.GetHex())); + claim.push_back(Pair("n", (int) itClaims->outPoint.n)); + claim.push_back(Pair("amount", ValueFromAmount(itClaims->nAmount))); + claim.push_back(Pair("height", itClaims->nHeight)); + claim.push_back(Pair("value", sValue)); + return claim; + } + } + } + } + return -1; +} UniValue gettotalclaimednames(const UniValue& params, bool fHelp) { @@ -710,6 +757,7 @@ static const CRPCCommand commands[] = { "Claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true }, { "Claimtrie", "getclaimsfortx", &getclaimsfortx, true }, { "Claimtrie", "getnameproof", &getnameproof, true }, + { "Claimtrie", "getclaimbyid", &getclaimbyid, true }, }; void RegisterClaimTrieRPCCommands(CRPCTable &tableRPC)