Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resolvename subdomains #916

Merged
merged 3 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/dotnav/names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ std::map<std::string, std::string> Consolidate(const NameDataValues& data, const
return ret;
}

std::map<std::string, std::map<std::string, std::string>> ConsolidateSubdomains(const NameDataValues& data, const int32_t& height)
{
std::map<std::string, std::map<std::string, std::string>> 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<std::string, std::string>& map) {
size_t ret = 0;

Expand Down
1 change: 1 addition & 0 deletions src/dotnav/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ std::vector<unsigned char> GetUpdateProgram(const std::string& name, const bls::
std::vector<unsigned char> GetUpdateFirstProgram(const std::string& name, const bls::G1Element& pk, const std::string& key, const std::string& value, const std::string& subdomain="");

std::map<std::string, std::string> Consolidate(const NameDataValues& data, const int32_t& nHeight, const std::string& subdomain="");
std::map<std::string, std::map<std::string, std::string>> ConsolidateSubdomains(const NameDataValues& data, const int32_t& nHeight);

size_t CalculateSize(const std::map<std::string, std::string>& map);
}
Expand Down
225 changes: 113 additions & 112 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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
Expand Down
37 changes: 35 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ".";
Expand Down Expand Up @@ -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;
}

Expand Down