|
|
@ -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); |
|
|
|
CPubKey pubKeyReserve; |
|
|
|
CScript addrName; |
|
|
|
const bool ok = keyName.GetReservedKey(pubKeyReserve, true); |
|
|
|
if (hasAddress) { |
|
|
|
assert(ok); |
|
|
|
CTxDestination dest = DecodeDestination(request.params[3].get_str()); |
|
|
|
CKeyID keyId = pubKeyReserve.GetID(); |
|
|
|
if (!IsValidDestination(dest)) { |
|
|
|
CScript redeemScript = GetScriptForDestination(WitnessV0KeyHash(keyId)); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); |
|
|
|
CScriptID scriptHash = CScriptID(redeemScript); |
|
|
|
} |
|
|
|
CScript addrName = GetScriptForDestination(scriptHash); |
|
|
|
addrName = GetScriptForDestination(dest); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
CPubKey pubKeyReserve; |
|
|
|
|
|
|
|
const bool ok = keyName.GetReservedKey(pubKeyReserve, true); |
|
|
|
|
|
|
|
assert(ok); |
|
|
|
|
|
|
|
CKeyID keyId = pubKeyReserve.GetID(); |
|
|
|
|
|
|
|
CScript redeemScript = GetScriptForDestination(WitnessV0KeyHash(keyId)); |
|
|
|
|
|
|
|
CScriptID scriptHash = CScriptID(redeemScript); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
keyName.KeepKey(); |
|
|
|
if (!hasAddress) { |
|
|
|
|
|
|
|
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; |
|
|
|