diff --git a/src/dotnav/names.cpp b/src/dotnav/names.cpp index bdf54170a..60e757a2a 100644 --- a/src/dotnav/names.cpp +++ b/src/dotnav/names.cpp @@ -129,6 +129,29 @@ std::map Consolidate(const NameDataValues& data, const return ret; } +std::map> ConsolidateSubdomains(const NameDataValues& data, const int32_t& height) +{ + std::map> ret; + + uint64_t nExpiry = ~(uint64_t)0; + + for (auto &it: data) { + if (it.second.key == "_expiry") + { + nExpiry = stoll(it.second.value); + } + } + + for (auto &it: data) { + if (nExpiry > height && it.first <= height && (it.second.subdomain != "")) { + if (it.second.value != "") + ret[it.second.subdomain][it.second.key] = it.second.value; + } + } + + return ret; +} + size_t CalculateSize(const std::map& map) { size_t ret = 0; diff --git a/src/dotnav/names.h b/src/dotnav/names.h index 10db4dd16..057fbca8f 100644 --- a/src/dotnav/names.h +++ b/src/dotnav/names.h @@ -34,6 +34,7 @@ std::vector GetUpdateProgram(const std::string& name, const bls:: std::vector GetUpdateFirstProgram(const std::string& name, const bls::G1Element& pk, const std::string& key, const std::string& value, const std::string& subdomain=""); std::map Consolidate(const NameDataValues& data, const int32_t& nHeight, const std::string& subdomain=""); +std::map> ConsolidateSubdomains(const NameDataValues& data, const int32_t& nHeight); size_t CalculateSize(const std::map& map); } diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 01de2561a..65a91916a 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -22,64 +22,13 @@ class CRPCConvertParam static const CRPCConvertParam vRPCConvertParams[] = { - { "stop", 0 }, - { "setmocktime", 0 }, - { "getaddednodeinfo", 0 }, - { "generate", 0 }, - { "generate", 1 }, - { "generatetoaddress", 0 }, - { "generatetoaddress", 2 }, - { "getnetworkhashps", 0 }, - { "getnetworkhashps", 1 }, - { "sendtoaddress", 1 }, - { "sendtoaddress", 5 }, - { "setaggregationfee", 0}, - { "settxfee", 0 }, - { "getreceivedbyaddress", 1 }, - { "getreceivedbyaccount", 1 }, - { "listreceivedbyaddress", 0 }, - { "listreceivedbyaddress", 1 }, - { "listreceivedbyaddress", 2 }, - { "listreceivedbyaccount", 0 }, - { "listreceivedbyaccount", 1 }, - { "listreceivedbyaccount", 2 }, - { "getbalance", 1 }, - { "getbalance", 2 }, - { "getblockhash", 0 }, - { "viewaggregationsession", 0}, - { "move", 2 }, - { "move", 3 }, - { "sendfrom", 2 }, - { "sendfrom", 3 }, - { "listtransactions", 1 }, - { "listtransactions", 2 }, - { "listtransactions", 3 }, - { "listaccounts", 0 }, - { "listaccounts", 1 }, - { "walletpassphrase", 1 }, - { "walletpassphrase", 2 }, - { "getblocktemplate", 0 }, - { "listsinceblock", 1 }, - { "listsinceblock", 2 }, - { "sendmany", 1 }, - { "sendmany", 2 }, - { "sendmany", 4 }, { "addmultisigaddress", 0 }, { "addmultisigaddress", 1 }, - { "createmultisig", 0 }, - { "createmultisig", 1 }, - { "createproposal", 2 }, - { "createproposal", 5 }, - { "createtoken", 2 }, - { "createnft", 2 }, { "burntoken", 1 }, - { "minttoken", 2 }, - { "mintnft", 1 }, - { "sendtoken", 2 }, - { "sendnft", 1 }, - { "sendnft", 3 }, - { "listtokens", 0 }, - { "createproposal", 7 }, + { "coinbaseoutputs", 0 }, + { "coinstakeinputs", 0 }, + { "coinstakeoutputs", 0 }, + { "consultationvote", 2 }, { "createconsultation", 1 }, { "createconsultation", 2 }, { "createconsultation", 3 }, @@ -92,83 +41,135 @@ static const CRPCConvertParam vRPCConvertParams[] = { "createconsultationwithanswers", 4 }, { "createconsultationwithanswers", 5 }, { "createconsultationwithanswers", 6 }, - { "proposeconsensuschange", 0}, - { "proposeconsensuschange", 1}, - { "proposeconsensuschange", 2}, - { "proposeconsensuschange", 3}, - { "proposecombinedconsensuschange", 0}, - { "proposecombinedconsensuschange", 1}, - { "proposecombinedconsensuschange", 2}, - { "proposecombinedconsensuschange", 3}, - { "consultationvote", 2 }, - { "support", 1 }, - { "proposeanswer", 1 }, - { "proposeanswer", 2 }, - { "proposeanswer", 3 }, + { "createmultisig", 0 }, + { "createmultisig", 1 }, + { "createnft", 2 }, { "createpaymentrequest", 3 }, { "createpaymentrequest", 4 }, { "createpaymentrequest", 5 }, - { "listunspent", 0 }, - { "listunspent", 1 }, - { "listunspent", 2 }, - { "listprivateunspent", 0 }, - { "listprivateunspent", 1 }, - { "listprivateunspent", 2 }, - { "getblock", 1 }, - { "getblockheader", 1 }, - { "gettransaction", 1 }, - { "getrawtransaction", 1 }, - { "getstakerscript", 1 }, + { "createproposal", 2 }, + { "createproposal", 5 }, + { "createproposal", 7 }, { "createrawtransaction", 0 }, { "createrawtransaction", 1 }, { "createrawtransaction", 3 }, { "createrawtransaction", 4 }, - { "signrawtransaction", 1 }, - { "signrawtransaction", 2 }, - { "sendrawtransaction", 1 }, + { "createtoken", 2 }, + { "donatefund", 1 }, + { "estimatefee", 0 }, + { "estimatepriority", 0 }, + { "estimatesmartfee", 0 }, + { "estimatesmartpriority", 0 }, + { "forcetransactions", 0 }, { "fundrawtransaction", 1 }, + { "generate", 0 }, + { "generate", 1 }, + { "generatetoaddress", 0 }, + { "generatetoaddress", 2 }, + { "getaddednodeinfo", 0 }, + { "getaddressbalance", 0}, + { "getaddressdeltas", 0}, + { "getaddresshistory", 0}, + { "getaddressmempool", 0}, + { "getaddresstxids", 0}, + { "getaddressutxos", 0}, + { "getbalance", 1 }, + { "getbalance", 2 }, + { "getblock", 1 }, + { "getblockhash", 0 }, + { "getblockhashes", 0 }, + { "getblockhashes", 1 }, + { "getblockhashes", 2 }, + { "getblockheader", 1 }, + { "getblocktemplate", 0 }, + { "getmempoolancestors", 1 }, + { "getmempooldescendants", 1 }, + { "getnetworkhashps", 0 }, + { "getnetworkhashps", 1 }, + { "getnewprivateaddress", 0 }, + { "getrawmempool", 0 }, + { "getrawtransaction", 1 }, + { "getreceivedbyaccount", 1 }, + { "getreceivedbyaddress", 1 }, + { "getspentinfo", 0}, + { "getstakerscript", 1 }, + { "gettransaction", 1 }, { "gettxout", 1 }, { "gettxout", 2 }, { "gettxoutproof", 0 }, - { "lockunspent", 0 }, - { "lockunspent", 1 }, - { "importprivkey", 2 }, { "importaddress", 2 }, { "importaddress", 3 }, + { "importprivkey", 2 }, { "importpubkey", 2 }, - { "verifychain", 0 }, - { "verifychain", 1 }, { "keypoolrefill", 0 }, - { "getrawmempool", 0 }, - { "estimatefee", 0 }, - { "estimatepriority", 0 }, - { "estimatesmartfee", 0 }, - { "estimatesmartpriority", 0 }, + { "listaccounts", 0 }, + { "listaccounts", 1 }, + { "listprivateunspent", 0 }, + { "listprivateunspent", 1 }, + { "listprivateunspent", 2 }, + { "listreceivedbyaccount", 0 }, + { "listreceivedbyaccount", 1 }, + { "listreceivedbyaccount", 2 }, + { "listreceivedbyaddress", 0 }, + { "listreceivedbyaddress", 1 }, + { "listreceivedbyaddress", 2 }, + { "listsinceblock", 1 }, + { "listsinceblock", 2 }, + { "listtokens", 0 }, + { "listtransactions", 1 }, + { "listtransactions", 2 }, + { "listtransactions", 3 }, + { "listunspent", 0 }, + { "listunspent", 1 }, + { "listunspent", 2 }, + { "lockunspent", 0 }, + { "lockunspent", 1 }, + { "mintnft", 1 }, + { "minttoken", 2 }, + { "move", 2 }, + { "move", 3 }, { "prioritisetransaction", 1 }, { "prioritisetransaction", 2 }, + { "proposeanswer", 1 }, + { "proposeanswer", 2 }, + { "proposeanswer", 3 }, + { "proposecombinedconsensuschange", 0}, + { "proposecombinedconsensuschange", 1}, + { "proposecombinedconsensuschange", 2}, + { "proposecombinedconsensuschange", 3}, + { "proposeconsensuschange", 0}, + { "proposeconsensuschange", 1}, + { "proposeconsensuschange", 2}, + { "proposeconsensuschange", 3}, + { "resolvename", 1 }, + { "scanviewkey", 1 }, + { "sendfrom", 2 }, + { "sendfrom", 3 }, + { "sendmany", 1 }, + { "sendmany", 2 }, + { "sendmany", 4 }, + { "sendnft", 1 }, + { "sendnft", 3 }, + { "sendrawtransaction", 1 }, + { "sendtoaddress", 1 }, + { "sendtoaddress", 5 }, + { "sendtoken", 2 }, + { "setaggregationfee", 0}, { "setban", 2 }, { "setban", 3 }, - { "getmempoolancestors", 1 }, - { "getmempooldescendants", 1 }, - { "getblockhashes", 0 }, - { "getblockhashes", 1 }, - { "getblockhashes", 2 }, - { "getspentinfo", 0}, - { "getaddresstxids", 0}, - { "getaddressbalance", 0}, - { "getaddresshistory", 0}, - { "getaddressdeltas", 0}, - { "getaddressutxos", 0}, - { "getaddressmempool", 0}, - { "staking", 0 }, { "setexclude", 0 }, - { "coinbaseoutputs", 0 }, - { "coinstakeoutputs", 0 }, - { "coinstakeinputs", 0 }, - { "forcetransactions", 0 }, - { "donatefund", 1 }, - { "getnewprivateaddress", 0 }, - { "scanviewkey", 1 }, + { "setmocktime", 0 }, + { "settxfee", 0 }, + { "signrawtransaction", 1 }, + { "signrawtransaction", 2 }, + { "staking", 0 }, + { "stop", 0 }, + { "support", 1 }, + { "verifychain", 0 }, + { "verifychain", 1 }, + { "viewaggregationsession", 0}, + { "walletpassphrase", 1 }, + { "walletpassphrase", 2 }, }; class CRPCConvertTable diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fddd10283..9304bcb20 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1323,13 +1323,20 @@ UniValue resolvename(const UniValue& params, bool fHelp) + HelpRequiringPassphrase() + "\nArguments:\n" "1. \"name\" (string, required) The name to resolve\n" + "2. \"subdomains\" (boolean, optional) Include subdomains\n" "\nExamples:\n" + HelpExampleCli("resolvename", "satoshi.nav") + + HelpExampleCli("resolvename", "satoshi.nav true") ); - if (!params[0].isStr() ) + if (!params[0].isStr()) throw JSONRPCError(RPC_TYPE_ERROR, "Name must be string"); + if (params.size() == 2 && !params[1].isBool()) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, argument 2 must be a boolean"); + + bool getSubdomains = params.size() > 1 && params[1].isBool() ? params[1].getBool() : false; + std::string sFullName = params[0].get_str(); std::string delimiter = "."; @@ -1358,12 +1365,38 @@ UniValue resolvename(const UniValue& params, bool fHelp) { return ret; } + auto mapData = DotNav::Consolidate(data, chainActive.Tip()->nHeight, subdomain); for (auto &it: mapData) { - ret.pushKV(it.first, it.second); + if (it.first.substr(0,1) == "_") { + ret.pushKV(it.first, it.second); + } + } + + if (getSubdomains && subdomain == "") { + auto subData = DotNav::ConsolidateSubdomains(data, chainActive.Tip()->nHeight); + UniValue subUniMain(UniValue::VOBJ); + + for (auto &it: subData) { + UniValue subUni(UniValue::VOBJ); + for (auto &sit: it.second) { + subUni.pushKV(sit.first, sit.second); + } + subUniMain.pushKV(it.first, subUni); + } + ret.pushKV("_subdomains", subUniMain); + } + + UniValue dotData(UniValue::VOBJ); + for (auto &it: mapData) { + if (it.first.substr(0,1) != "_") { + dotData.pushKV(it.first, it.second); + } } + ret.pushKV(".", dotData); + return ret; }