Browse Source

Added optional address to keva_put to transfer the namespace to the given address.

issue_19
Just Wonder 4 years ago
parent
commit
ced2ff10fc
  1. 24
      src/wallet/rpckeva.cpp

24
src/wallet/rpckeva.cpp

@ -210,15 +210,16 @@ UniValue keva_put(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (request.fHelp || request.params.size() != 3) { if (request.fHelp || request.params.size() < 3 || request.params.size() > 4) {
throw std::runtime_error ( throw std::runtime_error (
"keva_put \"namespace\" \"key\" \"value\"\n" "keva_put \"namespace\" \"key\" \"value\" \"address\" \n"
"\nInsert or update a key value pair in the given namespace.\n" "\nInsert or update a key value pair in the given namespace.\n"
+ HelpRequiringPassphrase (pwallet) + + HelpRequiringPassphrase (pwallet) +
"\nArguments:\n" "\nArguments:\n"
"1. \"namespace\" (string, required) the namespace to insert the key to\n" "1. \"namespace\" (string, required) the namespace to insert the key to\n"
"2. \"key\" (string, required) value for the key\n" "2. \"key\" (string, required) value for the key\n"
"3. \"value\" (string, required) value for the name\n" "3. \"value\" (string, required) value for the name\n"
"4. \"address\" (string, optional) transfer the namespace to the given address\n"
"\nResult:\n" "\nResult:\n"
"\"txid\" (string) the keva_put's txid\n" "\"txid\" (string) the keva_put's txid\n"
"\nExamples:\n" "\nExamples:\n"
@ -231,6 +232,12 @@ UniValue keva_put(const JSONRPCRequest& request)
RPCTypeCheckArgument(request.params[1], UniValue::VSTR); RPCTypeCheckArgument(request.params[1], UniValue::VSTR);
RPCTypeCheckArgument(request.params[2], UniValue::VSTR); RPCTypeCheckArgument(request.params[2], UniValue::VSTR);
bool hasAddress = false;
if (request.params.size() == 4) {
RPCTypeCheckArgument(request.params[3], UniValue::VSTR);
hasAddress = true;
}
ObserveSafeMode (); ObserveSafeMode ();
const std::string namespaceStr = request.params[0].get_str(); const std::string namespaceStr = request.params[0].get_str();
@ -262,13 +269,22 @@ UniValue keva_put(const JSONRPCRequest& request)
const CTxIn txIn(outp); const CTxIn txIn(outp);
CReserveKey keyName(pwallet); CReserveKey keyName(pwallet);
CScript addrName;
if (hasAddress) {
CTxDestination dest = DecodeDestination(request.params[3].get_str());
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
addrName = GetScriptForDestination(dest);
} else {
CPubKey pubKeyReserve; CPubKey pubKeyReserve;
const bool ok = keyName.GetReservedKey(pubKeyReserve, true); const bool ok = keyName.GetReservedKey(pubKeyReserve, true);
assert(ok); assert(ok);
CKeyID keyId = pubKeyReserve.GetID(); CKeyID keyId = pubKeyReserve.GetID();
CScript redeemScript = GetScriptForDestination(WitnessV0KeyHash(keyId)); CScript redeemScript = GetScriptForDestination(WitnessV0KeyHash(keyId));
CScriptID scriptHash = CScriptID(redeemScript); CScriptID scriptHash = CScriptID(redeemScript);
CScript addrName = GetScriptForDestination(scriptHash); addrName = GetScriptForDestination(scriptHash);
}
const CScript kevaScript = CKevaScript::buildKevaPut(addrName, nameSpace, key, value); const CScript kevaScript = CKevaScript::buildKevaPut(addrName, nameSpace, key, value);
@ -278,7 +294,9 @@ UniValue keva_put(const JSONRPCRequest& request)
SendMoneyToScript(pwallet, kevaScript, &txIn, empty, SendMoneyToScript(pwallet, kevaScript, &txIn, empty,
KEVA_LOCKED_AMOUNT, false, wtx, coinControl); KEVA_LOCKED_AMOUNT, false, wtx, coinControl);
if (!hasAddress) {
keyName.KeepKey(); keyName.KeepKey();
}
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.pushKV("txid", wtx.GetHash().GetHex()); obj.pushKV("txid", wtx.GetHash().GetHex());
return obj; return obj;

Loading…
Cancel
Save