diff --git a/src/wallet/rpckeva.cpp b/src/wallet/rpckeva.cpp index f152422f4..96699f2b8 100644 --- a/src/wallet/rpckeva.cpp +++ b/src/wallet/rpckeva.cpp @@ -96,14 +96,96 @@ UniValue keva_namespace(const JSONRPCRequest& request) return res; } -UniValue keva_put(const JSONRPCRequest& request) +UniValue keva_list_namespaces(const JSONRPCRequest& request) { CWallet* const pwallet = GetWalletForJSONRPCRequest(request); if (!EnsureWalletIsAvailable (pwallet, request.fHelp)) return NullUniValue; - if (request.fHelp - || (request.params.size () != 3)) + if (request.fHelp) + throw std::runtime_error ( + "keva_list_namespace\n" + "\nList all namespaces.\n" + + HelpRequiringPassphrase(pwallet) + + "\nArguments:\n" + "\nResult:\n" + "[\n" + " xxxxx: display_name (string) namespace id : (string) display name\n" + " ...\n" + "]\n" + "\nExamples:\n" + + HelpExampleCli("keva_list_namespace", "") + ); + + RPCTypeCheck (request.params, {UniValue::VSTR}); + + ObserveSafeMode (); + + std::map mapObjects; + { + LOCK2 (cs_main, pwallet->cs_wallet); + for (const auto& item : pwallet->mapWallet) + { + const CWalletTx& tx = item.second; + if (!tx.tx->IsKevacoin ()) + continue; + + CKevaScript kevaOp; + int nOut = -1; + for (unsigned i = 0; i < tx.tx->vout.size (); ++i) + { + const CKevaScript cur(tx.tx->vout[i].scriptPubKey); + if (cur.isKevaOp ()) + { + if (nOut != -1) { + LogPrintf ("ERROR: wallet contains tx with multiple name outputs"); + } else { + kevaOp = cur; + nOut = i; + } + } + } + + if (nOut == -1) { + continue; + } + + if (!kevaOp.isNamespaceRegistration() && !kevaOp.isAnyUpdate()) { + continue; + } + + const valtype& nameSpace = kevaOp.getOpNamespace(); + const CBlockIndex* pindex; + const int depth = tx.GetDepthInMainChain(pindex); + if (depth <= 0) { + continue; + } + + const bool mine = IsMine(*pwallet, kevaOp.getAddress ()); + CKevaData data; + if (mine && pcoinsTip->GetNamespace(nameSpace, data)) { + std::string displayName = ValtypeToString(data.getValue()); + mapObjects[nameSpace] = displayName; + } + } + } + + UniValue res(UniValue::VARR); + for (const auto& item : mapObjects) { + res.push_back(ValtypeToString(item.first) + " : " + item.second); + } + + return res; +} + +UniValue keva_put(const JSONRPCRequest& request) +{ + CWallet* const pwallet = GetWalletForJSONRPCRequest(request); + if (!EnsureWalletIsAvailable (pwallet, request.fHelp)) { + return NullUniValue; + } + + if (request.fHelp) { throw std::runtime_error ( "keva_put \"namespace\" \"key\" \"value\" (\"create_namespace\")\n" "\nUpdate a name and possibly transfer it.\n" @@ -117,9 +199,7 @@ UniValue keva_put(const JSONRPCRequest& request) "\nExamples:\n" + HelpExampleCli ("keva_put", "\"mynamespace\", \"new-key\", \"new-value\"") ); - - RPCTypeCheck (request.params, - {UniValue::VSTR, UniValue::VSTR, UniValue::VSTR, UniValue::VSTR}); + } ObserveSafeMode (); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c5d385868..df72834b7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3582,8 +3582,10 @@ extern UniValue removeprunedfunds(const JSONRPCRequest& request); extern UniValue importmulti(const JSONRPCRequest& request); extern UniValue rescanblockchain(const JSONRPCRequest& request); -extern UniValue keva_namespace(const JSONRPCRequest& request); // in rpckeva.cpp -extern UniValue keva_put(const JSONRPCRequest& request); // in rpckeva.cpp +// in rpckeva.cpp +extern UniValue keva_namespace(const JSONRPCRequest& request); +extern UniValue keva_put(const JSONRPCRequest& request); +extern UniValue keva_list_namespaces(const JSONRPCRequest& request); static const CRPCCommand commands[] = { // category name actor (function) argNames @@ -3643,7 +3645,8 @@ static const CRPCCommand commands[] = { "generating", "generate", &generate, {"nblocks","maxtries"} }, // Kevacoin-specific wallet calls. - { "kevacoin", "keva_namespace", &keva_namespace, {"namespace", "key", "value", "create_namespace"} }, + { "kevacoin", "keva_namespace", &keva_namespace, {"display_name"} }, + { "kevacoin", "keva_list_namespaces", &keva_list_namespaces, {} }, { "kevacoin", "keva_put", &keva_put, {"namespace", "key", "value", "put_value"} } };