mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-03-12 05:31:14 +00:00
Implemented keva_group_join.
This commit is contained in:
parent
da100e7634
commit
9ad1e217b5
@ -150,9 +150,13 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "keva_filter", 3, "from"},
|
||||
{ "keva_filter", 4, "nb"},
|
||||
|
||||
{ "keva_show_group", 1, "maxage"},
|
||||
{ "keva_show_group", 2, "from"},
|
||||
{ "keva_show_group", 3, "nb"},
|
||||
{ "keva_group_show", 1, "maxage"},
|
||||
{ "keva_group_show", 2, "from"},
|
||||
{ "keva_group_show", 3, "nb"},
|
||||
|
||||
{ "keva_group_filter", 3, "maxage"},
|
||||
{ "keva_group_filter", 4, "from"},
|
||||
{ "keva_group_filter", 5, "nb"},
|
||||
};
|
||||
|
||||
class CRPCConvertTable
|
||||
|
@ -415,13 +415,18 @@ UniValue keva_group_filter(const JSONRPCRequest& request)
|
||||
|
||||
valtype key;
|
||||
CKevaData data;
|
||||
valtype displayKey = ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY);
|
||||
for (auto iterNS = namespaces.begin(); iterNS != namespaces.end(); ++iterNS) {
|
||||
std::unique_ptr<CKevaIterator> iter(pcoinsTip->IterateKeys(*iterNS));
|
||||
while (iter->next(key, data)) {
|
||||
if (key == displayKey) {
|
||||
continue;
|
||||
}
|
||||
const int age = chainActive.Height() - data.getHeight();
|
||||
assert(age >= 0);
|
||||
if (maxage != 0 && age >= maxage)
|
||||
if (maxage != 0 && age >= maxage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (haveRegexp) {
|
||||
const std::string keyStr = ValtypeToString(key);
|
||||
@ -643,11 +648,11 @@ getNamespaceInfo(const valtype& namespaceId, const valtype& name, const COutPoin
|
||||
return obj;
|
||||
}
|
||||
|
||||
UniValue keva_show_group(const JSONRPCRequest& request)
|
||||
UniValue keva_group_show(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.size() > 6 || request.params.size() == 0)
|
||||
throw std::runtime_error(
|
||||
"keva_show_group (\"namespaceId\" (\"regexp\" (\"from\" (\"nb\" (\"stat\")))))\n"
|
||||
"keva_group_show (\"namespaceId\" (\"regexp\" (\"from\" (\"nb\" (\"stat\")))))\n"
|
||||
"\nList namespaces that are in the same group as the given namespace.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"namespace\" (string) namespace Id\n"
|
||||
@ -661,8 +666,8 @@ UniValue keva_show_group(const JSONRPCRequest& request)
|
||||
" ...\n"
|
||||
"]\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli ("keva_show_group", "NamespaceId")
|
||||
+ HelpExampleCli ("keva_show_group", "NamespaceId 96000 0 0 \"stat\"")
|
||||
+ HelpExampleCli ("keva_group_show", "NamespaceId")
|
||||
+ HelpExampleCli ("keva_group_show", "NamespaceId 96000 0 0 \"stat\"")
|
||||
);
|
||||
|
||||
RPCTypeCheck(request.params, {
|
||||
@ -822,7 +827,7 @@ static const CRPCCommand commands[] =
|
||||
// --------------------- ------------------------ ----------------------- ----------
|
||||
{ "kevacoin", "keva_get", &keva_get, {"namespace", "key"} },
|
||||
{ "kevacoin", "keva_filter", &keva_filter, {"namespace", "regexp", "from", "nb", "stat"} },
|
||||
{ "kevacoin", "keva_show_group", &keva_show_group, {"namespace", "from", "nb", "stat"} },
|
||||
{ "kevacoin", "keva_group_show", &keva_group_show, {"namespace", "from", "nb", "stat"} },
|
||||
{ "kevacoin", "keva_group_get", &keva_group_get, {"namespace", "key", "initiator"} },
|
||||
{ "kevacoin", "keva_group_filter", &keva_group_filter, {"namespace", "initiator", "regexp", "from", "nb", "stat"} }
|
||||
};
|
||||
|
@ -460,3 +460,79 @@ UniValue keva_pending(const JSONRPCRequest& request)
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
UniValue keva_group_join(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_group_join \"my_namespace\" \"other_namespace\"\n"
|
||||
"\nInsert or update a key value pair in the given namespace.\n"
|
||||
+ HelpRequiringPassphrase (pwallet) +
|
||||
"\nArguments:\n"
|
||||
"1. \"my_namespace\" (string, required) the namespace to join to <other_namespace>\n"
|
||||
"2. \"other_namespace\" (string, required) the target namespace to join to\n"
|
||||
"\nResult:\n"
|
||||
"\"txid\" (string) the keva_put's txid\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli ("keva_group_join", "\"my_namespace\", \"other_namespace\"")
|
||||
);
|
||||
}
|
||||
|
||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR});
|
||||
RPCTypeCheckArgument(request.params[0], UniValue::VSTR);
|
||||
RPCTypeCheckArgument(request.params[1], UniValue::VSTR);
|
||||
|
||||
ObserveSafeMode ();
|
||||
|
||||
const std::string myNamespaceStr = request.params[0].get_str();
|
||||
valtype myNamespace;
|
||||
if (!DecodeKevaNamespace(myNamespaceStr, Params(), myNamespace)) {
|
||||
throw JSONRPCError (RPC_INVALID_PARAMETER, "invalid namespace id for my_namespace");
|
||||
}
|
||||
|
||||
const std::string otherNamespaceStr = request.params[1].get_str();
|
||||
valtype otherNamespace;
|
||||
if (!DecodeKevaNamespace(otherNamespaceStr, Params(), otherNamespace)) {
|
||||
throw JSONRPCError (RPC_INVALID_PARAMETER, "invalid namespace id for other_namespace");
|
||||
}
|
||||
|
||||
//TODO: check other_namespace exists.
|
||||
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
|
||||
COutput output;
|
||||
if (!pwallet->FindKevaCoin(output, myNamespaceStr)) {
|
||||
throw JSONRPCError (RPC_TRANSACTION_ERROR, "this namespace can not be updated");
|
||||
}
|
||||
const COutPoint outp(output.tx->GetHash(), output.i);
|
||||
const CTxIn txIn(outp);
|
||||
|
||||
CReserveKey keyName(pwallet);
|
||||
CPubKey pubKeyReserve;
|
||||
const bool ok = keyName.GetReservedKey(pubKeyReserve, true);
|
||||
assert(ok);
|
||||
CKeyID keyId = pubKeyReserve.GetID();
|
||||
CScript redeemScript = GetScriptForDestination(WitnessV0KeyHash(keyId));
|
||||
CScriptID scriptHash = CScriptID(redeemScript);
|
||||
CScript addrName = GetScriptForDestination(scriptHash);
|
||||
|
||||
valtype dummy = ValtypeFromString(std::string("1"));
|
||||
valtype key = ValtypeFromString(CKevaData::ASSOCIATE_PREFIX + otherNamespaceStr);
|
||||
const CScript kevaScript = CKevaScript::buildKevaPut(addrName, myNamespace, key, dummy);
|
||||
|
||||
CCoinControl coinControl;
|
||||
CWalletTx wtx;
|
||||
valtype empty;
|
||||
SendMoneyToScript(pwallet, kevaScript, &txIn, empty,
|
||||
KEVA_LOCKED_AMOUNT, false, wtx, coinControl);
|
||||
|
||||
keyName.KeepKey();
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("txid", wtx.GetHash().GetHex());
|
||||
return obj;
|
||||
}
|
||||
|
@ -3722,7 +3722,7 @@ extern UniValue keva_delete(const JSONRPCRequest& request);
|
||||
extern UniValue keva_get(const JSONRPCRequest& request);
|
||||
extern UniValue keva_list_namespaces(const JSONRPCRequest& request);
|
||||
extern UniValue keva_pending(const JSONRPCRequest& request);
|
||||
extern UniValue keva_filter(const JSONRPCRequest& request);
|
||||
extern UniValue keva_group_join(const JSONRPCRequest& request);
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
{ // category name actor (function) argNames
|
||||
@ -3787,7 +3787,8 @@ static const CRPCCommand commands[] =
|
||||
{ "kevacoin", "keva_list_namespaces", &keva_list_namespaces, {} },
|
||||
{ "kevacoin", "keva_put", &keva_put, {"namespace", "key", "value"} },
|
||||
{ "kevacoin", "keva_delete", &keva_delete, {"namespace", "key"} },
|
||||
{ "kevacoin", "keva_pending", &keva_pending, {"namespace"} }
|
||||
{ "kevacoin", "keva_pending", &keva_pending, {"namespace"} },
|
||||
{ "kevacoin", "keva_group_join", &keva_group_join, {"my_namespace", "other_namespace"} }
|
||||
};
|
||||
|
||||
void RegisterWalletRPCCommands(CRPCTable &t)
|
||||
|
Loading…
x
Reference in New Issue
Block a user