create an rpc command to return all claims in the trie
This commit is contained in:
parent
a6984a9d72
commit
f4d5f23486
3 changed files with 81 additions and 0 deletions
|
@ -3,6 +3,85 @@
|
||||||
#include "rpcserver.h"
|
#include "rpcserver.h"
|
||||||
#include "univalue/univalue.h"
|
#include "univalue/univalue.h"
|
||||||
|
|
||||||
|
UniValue getclaimsintrie(const UniValue& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() > 0)
|
||||||
|
throw std::runtime_error(
|
||||||
|
"getclaimsintrie\n"
|
||||||
|
"Return all claims in the name trie.\n"
|
||||||
|
"Arguments:\n"
|
||||||
|
"None\n"
|
||||||
|
"Result: \n"
|
||||||
|
"[\n"
|
||||||
|
" {\n"
|
||||||
|
" \"name\" (string) the name claimed\n"
|
||||||
|
" \"claims\": [ (array of object) the claims for this name\n"
|
||||||
|
" {\n"
|
||||||
|
" \"txid\" (string) the txid of the claim\n"
|
||||||
|
" \"n\" (numeric) the vout value of the claim\n"
|
||||||
|
" \"amount\" (numeric) txout amount\n"
|
||||||
|
" \"height\" (numeric) the height of the block in which this transaction is located\n"
|
||||||
|
" \"value\" (string) the value of this claim\n"
|
||||||
|
" }\n"
|
||||||
|
" ]\n"
|
||||||
|
" }\n"
|
||||||
|
"]\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
LOCK(cs_main);
|
||||||
|
UniValue ret(UniValue::VARR);
|
||||||
|
|
||||||
|
CCoinsViewCache view(pcoinsTip);
|
||||||
|
std::vector<namedNodeType> nodes = pnccTrie->flattenTrie();
|
||||||
|
|
||||||
|
CNodeValue val;
|
||||||
|
|
||||||
|
for (std::vector<namedNodeType>::iterator it = nodes.begin(); it != nodes.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it->second.getBestValue(val))
|
||||||
|
{
|
||||||
|
UniValue node(UniValue::VOBJ);
|
||||||
|
node.push_back(Pair("name", it->first));
|
||||||
|
UniValue claims(UniValue::VARR);
|
||||||
|
for (std::vector<CNodeValue>::iterator itClaims = it->second.values.begin(); itClaims != it->second.values.end(); ++itClaims)
|
||||||
|
{
|
||||||
|
UniValue claim(UniValue::VOBJ);
|
||||||
|
claim.push_back(Pair("txid", itClaims->txhash.GetHex()));
|
||||||
|
claim.push_back(Pair("n", (int)itClaims->nOut));
|
||||||
|
claim.push_back(Pair("amount", itClaims->nAmount));
|
||||||
|
claim.push_back(Pair("height", itClaims->nHeight));
|
||||||
|
const CCoins* coin = view.AccessCoins(val.txhash);
|
||||||
|
if (!coin)
|
||||||
|
{
|
||||||
|
LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n",
|
||||||
|
__func__, val.txhash.GetHex());
|
||||||
|
claim.push_back(Pair("error", "No value found for claim"));
|
||||||
|
}
|
||||||
|
else if (coin->vout.size() < val.nOut || coin->vout[val.nOut].IsNull())
|
||||||
|
{
|
||||||
|
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, val.txhash.GetHex());
|
||||||
|
claim.push_back(Pair("error", "Txout spent"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int op;
|
||||||
|
std::vector<std::vector<unsigned char> > vvchParams;
|
||||||
|
if (!DecodeNCCScript(coin->vout[val.nOut].scriptPubKey, op, vvchParams))
|
||||||
|
{
|
||||||
|
LogPrintf("%s: the specified txout of %s does not have an NCC command\n", __func__, val.txhash.GetHex());
|
||||||
|
}
|
||||||
|
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
|
||||||
|
claim.push_back(Pair("value", sValue));
|
||||||
|
}
|
||||||
|
claims.push_back(claim);
|
||||||
|
}
|
||||||
|
node.push_back(Pair("claims", claims));
|
||||||
|
ret.push_back(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
UniValue getnametrie(const UniValue& params, bool fHelp)
|
UniValue getnametrie(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() > 0)
|
if (fHelp || params.size() > 0)
|
||||||
|
|
|
@ -380,6 +380,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||||
#endif // ENABLE_WALLET
|
#endif // ENABLE_WALLET
|
||||||
|
|
||||||
/* NCC trie */
|
/* NCC trie */
|
||||||
|
{ "nametrie", "getclaimsintrie", &getclaimsintrie, true },
|
||||||
{ "nametrie", "getnametrie", &getnametrie, true },
|
{ "nametrie", "getnametrie", &getnametrie, true },
|
||||||
{ "nametrie", "getvalueforname", &getvalueforname, true },
|
{ "nametrie", "getvalueforname", &getvalueforname, true },
|
||||||
{ "nametrie", "gettotalclaimednames", &gettotalclaimednames, true },
|
{ "nametrie", "gettotalclaimednames", &gettotalclaimednames, true },
|
||||||
|
|
|
@ -241,6 +241,7 @@ extern UniValue getchaintips(const UniValue& params, bool fHelp);
|
||||||
extern UniValue invalidateblock(const UniValue& params, bool fHelp);
|
extern UniValue invalidateblock(const UniValue& params, bool fHelp);
|
||||||
extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
|
extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
|
||||||
|
|
||||||
|
extern UniValue getclaimsintrie(const UniValue& params, bool fHelp); // in rpcncctrie.cpp
|
||||||
extern UniValue getnametrie(const UniValue& params, bool fHelp); // in rpcncctrie.cpp
|
extern UniValue getnametrie(const UniValue& params, bool fHelp); // in rpcncctrie.cpp
|
||||||
extern UniValue getvalueforname(const UniValue& params, bool fHelp);
|
extern UniValue getvalueforname(const UniValue& params, bool fHelp);
|
||||||
extern UniValue gettotalclaimednames(const UniValue& params, bool fHelp);
|
extern UniValue gettotalclaimednames(const UniValue& params, bool fHelp);
|
||||||
|
|
Loading…
Reference in a new issue