Browse Source

Implemented keva_list_namespaces.

cn
Jianping Wu 6 years ago
parent
commit
0d808fcdd0
  1. 92
      src/wallet/rpckeva.cpp
  2. 9
      src/wallet/rpcwallet.cpp

92
src/wallet/rpckeva.cpp

@ -96,14 +96,96 @@ UniValue keva_namespace(const JSONRPCRequest& request) @@ -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<valtype, std::string> 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) @@ -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 ();

9
src/wallet/rpcwallet.cpp

@ -3582,8 +3582,10 @@ extern UniValue removeprunedfunds(const JSONRPCRequest& request); @@ -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[] = @@ -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"} }
};

Loading…
Cancel
Save