mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-27 07:14:48 +00:00
Implemented keva_get.
This commit is contained in:
parent
0d808fcdd0
commit
11746152dc
@ -185,7 +185,7 @@ UniValue keva_put(const JSONRPCRequest& request)
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (request.fHelp) {
|
||||
if (request.fHelp || request.params.size() != 3) {
|
||||
throw std::runtime_error (
|
||||
"keva_put \"namespace\" \"key\" \"value\" (\"create_namespace\")\n"
|
||||
"\nUpdate a name and possibly transfer it.\n"
|
||||
@ -201,6 +201,11 @@ UniValue keva_put(const JSONRPCRequest& request)
|
||||
);
|
||||
}
|
||||
|
||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR, UniValue::VSTR});
|
||||
RPCTypeCheckArgument(request.params[0], UniValue::VSTR);
|
||||
RPCTypeCheckArgument(request.params[1], UniValue::VSTR);
|
||||
RPCTypeCheckArgument(request.params[2], UniValue::VSTR);
|
||||
|
||||
ObserveSafeMode ();
|
||||
|
||||
const std::string namespaceStr = request.params[0].get_str ();
|
||||
@ -268,3 +273,52 @@ UniValue keva_put(const JSONRPCRequest& request)
|
||||
|
||||
return wtx.GetHash().GetHex();
|
||||
}
|
||||
|
||||
UniValue keva_get(const JSONRPCRequest& request)
|
||||
{
|
||||
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
|
||||
if (!EnsureWalletIsAvailable (pwallet, request.fHelp)) {
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (request.fHelp || request.params.size() != 2) {
|
||||
throw std::runtime_error (
|
||||
"keva_get \"namespace\" \"key\"\n"
|
||||
"\nGet value of the given key.\n"
|
||||
+ HelpRequiringPassphrase (pwallet) +
|
||||
"\nArguments:\n"
|
||||
"1. \"namespace\" (string, required) the namespace to insert the key to\n"
|
||||
"2. \"key\" (string, required) value for the key\n"
|
||||
"\nResult:\n"
|
||||
"\"value\" (string) the value associated with the key\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli ("keva_get", "\"namespace_id\", \"key\"")
|
||||
);
|
||||
}
|
||||
|
||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR});
|
||||
RPCTypeCheckArgument(request.params[0], UniValue::VSTR);
|
||||
RPCTypeCheckArgument(request.params[1], UniValue::VSTR);
|
||||
|
||||
ObserveSafeMode ();
|
||||
|
||||
const std::string namespaceStr = request.params[0].get_str ();
|
||||
const valtype nameSpace = ValtypeFromString (namespaceStr);
|
||||
if (nameSpace.size () > MAX_NAMESPACE_LENGTH)
|
||||
throw JSONRPCError (RPC_INVALID_PARAMETER, "the namespace is too long");
|
||||
|
||||
const std::string keyStr = request.params[1].get_str ();
|
||||
const valtype key = ValtypeFromString (keyStr);
|
||||
if (key.size () > MAX_KEY_LENGTH)
|
||||
throw JSONRPCError (RPC_INVALID_PARAMETER, "the key is too long");
|
||||
|
||||
CKevaData data;
|
||||
{
|
||||
LOCK (cs_main);
|
||||
if (!pcoinsTip->GetName(nameSpace, key, data)) {
|
||||
throw JSONRPCError (RPC_TRANSACTION_ERROR, "key not found");
|
||||
}
|
||||
}
|
||||
|
||||
return ValtypeToString(data.getValue());
|
||||
}
|
||||
|
@ -3585,6 +3585,7 @@ extern UniValue rescanblockchain(const JSONRPCRequest& request);
|
||||
// in rpckeva.cpp
|
||||
extern UniValue keva_namespace(const JSONRPCRequest& request);
|
||||
extern UniValue keva_put(const JSONRPCRequest& request);
|
||||
extern UniValue keva_get(const JSONRPCRequest& request);
|
||||
extern UniValue keva_list_namespaces(const JSONRPCRequest& request);
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
@ -3647,7 +3648,8 @@ static const CRPCCommand commands[] =
|
||||
// Kevacoin-specific wallet calls.
|
||||
{ "kevacoin", "keva_namespace", &keva_namespace, {"display_name"} },
|
||||
{ "kevacoin", "keva_list_namespaces", &keva_list_namespaces, {} },
|
||||
{ "kevacoin", "keva_put", &keva_put, {"namespace", "key", "value", "put_value"} }
|
||||
{ "kevacoin", "keva_put", &keva_put, {"namespace", "key", "value"} },
|
||||
{ "kevacoin", "keva_get", &keva_get, {"namespace", "key"} }
|
||||
};
|
||||
|
||||
void RegisterWalletRPCCommands(CRPCTable &t)
|
||||
|
Loading…
x
Reference in New Issue
Block a user