mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #19717: rpc: Assert that RPCArg names are equal to CRPCCommand ones (mining,zmq,rpcdump)
fa3d9ce3254882c545d700990fe8e9a678f31eed rpc: Assert that RPCArg names are equal to CRPCCommand ones (rpcdump) (MarcoFalke) fa32c1d5ec25bc53bf989a8ae68e688593d2859d rpc: Assert that RPCArg names are equal to CRPCCommand ones (zmq) (MarcoFalke) faaa46dc204d6d714f71dbc6f0bf02215dba0f0f rpc: Assert that RPCArg names are equal to CRPCCommand ones (mining) (MarcoFalke) fa93bc14c7411a108dd024d391344fabf0f76369 rpc: Remove unused return type from appendCommand (MarcoFalke) Pull request description: This is split out from #18531 to just touch the RPC methods in misc. Description from the main pr: ### Motivation RPCArg names in the rpc help are currently only used for documentation. However, in the future they could be used to teach the server the named arguments. Named arguments are currently registered by the `CRPCCommand`s and duplicate the RPCArg names from the documentation. This redundancy is fragile, and has lead to errors in the past (despite having linters to catch those kind of errors). See section "bugs found" for a list of bugs that have been found as a result of the changes here. ### Changes The changes here add an assert in the `CRPCCommand` constructor that the RPCArg names are identical to the ones in the `CRPCCommand`. ### Future work > Here or follow up, makes sense to also assert type of returned UniValue? Sure, but let's not get ahead of ourselves. I am going to submit any further works as follow-ups, including: * Removing the CRPCCommand arguments, now that they are asserted to be equal and thus redundant * Removing all python regex linters on the args, now that RPCMan can be used to generate any output, including the cli.cpp table * Auto-formatting and sanity checking the RPCExamples with RPCMan * Checking passed-in json in self-check. Removing redundant checks * Checking returned json against documentation to avoid regressions or false documentation * Compile the RPC documentation at compile-time to ensure it doesn't change at runtime and is completely static ### Bugs found * The assert identified issue #18607 * The changes itself fixed bug #19250 ACKs for top commit: fjahr: tested ACK fa3d9ce3254882c545d700990fe8e9a678f31eed promag: Code review ACK fa3d9ce3254882c545d700990fe8e9a678f31eed. Tree-SHA512: 068ade4b55cc195868d53b7f9a27151d45b440857bb069e261a49d102a49a38fdba5d68868516a1d66a54a73ba34681362f934ded7349e894042bde873b75719
This commit is contained in:
parent
860d31f504
commit
7ac1ee0fb4
@ -94,9 +94,9 @@ static UniValue GetNetworkHashPS(int lookup, int height, const CChain& active_ch
|
|||||||
return workDiff.getdouble() / timeDiff;
|
return workDiff.getdouble() / timeDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue getnetworkhashps(const JSONRPCRequest& request)
|
static RPCHelpMan getnetworkhashps()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"getnetworkhashps",
|
return RPCHelpMan{"getnetworkhashps",
|
||||||
"\nReturns the estimated network hashes per second based on the last n blocks.\n"
|
"\nReturns the estimated network hashes per second based on the last n blocks.\n"
|
||||||
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
|
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
|
||||||
"Pass in [height] to estimate the network speed at the time when a certain block was found.\n",
|
"Pass in [height] to estimate the network speed at the time when a certain block was found.\n",
|
||||||
@ -110,11 +110,14 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("getnetworkhashps", "")
|
HelpExampleCli("getnetworkhashps", "")
|
||||||
+ HelpExampleRpc("getnetworkhashps", "")
|
+ HelpExampleRpc("getnetworkhashps", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
|
|
||||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1, chainman.ActiveChain());
|
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1, chainman.ActiveChain());
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_MINER
|
#if ENABLE_MINER
|
||||||
@ -218,9 +221,9 @@ static bool getScriptFromDescriptor(const std::string& descriptor, CScript& scri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue generatetodescriptor(const JSONRPCRequest& request)
|
static RPCHelpMan generatetodescriptor()
|
||||||
{
|
{
|
||||||
RPCHelpMan{
|
return RPCHelpMan{
|
||||||
"generatetodescriptor",
|
"generatetodescriptor",
|
||||||
"\nMine blocks immediately to a specified descriptor (before the RPC call returns)\n",
|
"\nMine blocks immediately to a specified descriptor (before the RPC call returns)\n",
|
||||||
{
|
{
|
||||||
@ -236,9 +239,8 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
|
|||||||
},
|
},
|
||||||
RPCExamples{
|
RPCExamples{
|
||||||
"\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
|
"\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
|
||||||
}
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
.Check(request);
|
{
|
||||||
|
|
||||||
const int num_blocks{request.params[0].get_int()};
|
const int num_blocks{request.params[0].get_int()};
|
||||||
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
|
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
|
||||||
|
|
||||||
@ -254,11 +256,13 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
|
|||||||
LLMQContext& llmq_ctx = EnsureLLMQContext(node);
|
LLMQContext& llmq_ctx = EnsureLLMQContext(node);
|
||||||
|
|
||||||
return generateBlocks(chainman, *node.evodb, *node.chain_helper, llmq_ctx, mempool, coinbase_script, num_blocks, max_tries);
|
return generateBlocks(chainman, *node.evodb, *node.chain_helper, llmq_ctx, mempool, coinbase_script, num_blocks, max_tries);
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue generatetoaddress(const JSONRPCRequest& request)
|
static RPCHelpMan generatetoaddress()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"generatetoaddress",
|
return RPCHelpMan{"generatetoaddress",
|
||||||
"\nMine blocks immediately to a specified address (before the RPC call returns)\n",
|
"\nMine blocks immediately to a specified address (before the RPC call returns)\n",
|
||||||
{
|
{
|
||||||
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
|
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
|
||||||
@ -275,8 +279,8 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
|
|||||||
+ HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
|
+ HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
|
||||||
+ "If you are using the " PACKAGE_NAME " wallet, you can get a new address to send the newly generated coins to with:\n"
|
+ "If you are using the " PACKAGE_NAME " wallet, you can get a new address to send the newly generated coins to with:\n"
|
||||||
+ HelpExampleCli("getnewaddress", "")},
|
+ HelpExampleCli("getnewaddress", "")},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
const int num_blocks{request.params[0].get_int()};
|
const int num_blocks{request.params[0].get_int()};
|
||||||
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
|
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
|
||||||
|
|
||||||
@ -293,11 +297,13 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
|
|||||||
CScript coinbase_script = GetScriptForDestination(destination);
|
CScript coinbase_script = GetScriptForDestination(destination);
|
||||||
|
|
||||||
return generateBlocks(chainman, *node.evodb, *node.chain_helper, llmq_ctx, mempool, coinbase_script, num_blocks, max_tries);
|
return generateBlocks(chainman, *node.evodb, *node.chain_helper, llmq_ctx, mempool, coinbase_script, num_blocks, max_tries);
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue generateblock(const JSONRPCRequest& request)
|
static RPCHelpMan generateblock()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"generateblock",
|
return RPCHelpMan{"generateblock",
|
||||||
"\nMine a block with a set of ordered transactions immediately to a specified address or descriptor (before the RPC call returns)\n",
|
"\nMine a block with a set of ordered transactions immediately to a specified address or descriptor (before the RPC call returns)\n",
|
||||||
{
|
{
|
||||||
{"address/descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The address or descriptor to send the newly generated coins to."},
|
{"address/descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The address or descriptor to send the newly generated coins to."},
|
||||||
@ -319,8 +325,8 @@ static UniValue generateblock(const JSONRPCRequest& request)
|
|||||||
"\nGenerate a block to myaddress, with txs rawtx and mempool_txid\n"
|
"\nGenerate a block to myaddress, with txs rawtx and mempool_txid\n"
|
||||||
+ HelpExampleCli("generateblock", R"("myaddress" '["rawtx", "mempool_txid"]')")
|
+ HelpExampleCli("generateblock", R"("myaddress" '["rawtx", "mempool_txid"]')")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
const auto address_or_descriptor = request.params[0].get_str();
|
const auto address_or_descriptor = request.params[0].get_str();
|
||||||
CScript coinbase_script;
|
CScript coinbase_script;
|
||||||
std::string error;
|
std::string error;
|
||||||
@ -405,6 +411,8 @@ static UniValue generateblock(const JSONRPCRequest& request)
|
|||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.pushKV("hash", block_hash.GetHex());
|
obj.pushKV("hash", block_hash.GetHex());
|
||||||
return obj;
|
return obj;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static UniValue generatetoaddress(const JSONRPCRequest& request)
|
static UniValue generatetoaddress(const JSONRPCRequest& request)
|
||||||
@ -421,7 +429,7 @@ static UniValue generateblock(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
#endif // ENABLE_MINER
|
#endif // ENABLE_MINER
|
||||||
|
|
||||||
static UniValue generate(const JSONRPCRequest& request)
|
static RPCHelpMan generate()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{"generate", "has been replaced by the -generate cli option. Refer to -help for more information.", {}, {}, RPCExamples{""}, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
|
return RPCHelpMan{"generate", "has been replaced by the -generate cli option. Refer to -help for more information.", {}, {}, RPCExamples{""}, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
|
||||||
|
|
||||||
@ -433,9 +441,9 @@ static UniValue generate(const JSONRPCRequest& request)
|
|||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue getmininginfo(const JSONRPCRequest& request)
|
static RPCHelpMan getmininginfo()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"getmininginfo",
|
return RPCHelpMan{"getmininginfo",
|
||||||
"\nReturns a json object containing mining-related information.",
|
"\nReturns a json object containing mining-related information.",
|
||||||
{},
|
{},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
@ -454,7 +462,8 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("getmininginfo", "")
|
HelpExampleCli("getmininginfo", "")
|
||||||
+ HelpExampleRpc("getmininginfo", "")
|
+ HelpExampleRpc("getmininginfo", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
|
|
||||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
|
|
||||||
@ -469,18 +478,20 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
|
|||||||
if (BlockAssembler::m_last_block_size) obj.pushKV("currentblocksize", *BlockAssembler::m_last_block_size);
|
if (BlockAssembler::m_last_block_size) obj.pushKV("currentblocksize", *BlockAssembler::m_last_block_size);
|
||||||
if (BlockAssembler::m_last_block_num_txs) obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs);
|
if (BlockAssembler::m_last_block_num_txs) obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs);
|
||||||
obj.pushKV("difficulty", (double)GetDifficulty(active_chain.Tip()));
|
obj.pushKV("difficulty", (double)GetDifficulty(active_chain.Tip()));
|
||||||
obj.pushKV("networkhashps", getnetworkhashps(request));
|
obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
|
||||||
obj.pushKV("pooledtx", (uint64_t)mempool.size());
|
obj.pushKV("pooledtx", (uint64_t)mempool.size());
|
||||||
obj.pushKV("chain", Params().NetworkIDString());
|
obj.pushKV("chain", Params().NetworkIDString());
|
||||||
obj.pushKV("warnings", GetWarnings(false).original);
|
obj.pushKV("warnings", GetWarnings(false).original);
|
||||||
return obj;
|
return obj;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
|
// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
|
||||||
static UniValue prioritisetransaction(const JSONRPCRequest& request)
|
static RPCHelpMan prioritisetransaction()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"prioritisetransaction",
|
return RPCHelpMan{"prioritisetransaction",
|
||||||
"Accepts the transaction into mined blocks at a higher (or lower) priority\n",
|
"Accepts the transaction into mined blocks at a higher (or lower) priority\n",
|
||||||
{
|
{
|
||||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id."},
|
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id."},
|
||||||
@ -495,8 +506,9 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("prioritisetransaction", "\"txid\" 10000")
|
HelpExampleCli("prioritisetransaction", "\"txid\" 10000")
|
||||||
+ HelpExampleRpc("prioritisetransaction", "\"txid\", 10000")
|
+ HelpExampleRpc("prioritisetransaction", "\"txid\", 10000")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
|
||||||
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
uint256 hash(ParseHashV(request.params[0].get_str(), "txid"));
|
uint256 hash(ParseHashV(request.params[0].get_str(), "txid"));
|
||||||
@ -504,6 +516,8 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
EnsureAnyMemPool(request.context).PrioritiseTransaction(hash, nAmount);
|
EnsureAnyMemPool(request.context).PrioritiseTransaction(hash, nAmount);
|
||||||
return true;
|
return true;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -535,9 +549,9 @@ static std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue getblocktemplate(const JSONRPCRequest& request)
|
static RPCHelpMan getblocktemplate()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"getblocktemplate",
|
return RPCHelpMan{"getblocktemplate",
|
||||||
"\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
|
"\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
|
||||||
"It returns data needed to construct a block to work on.\n"
|
"It returns data needed to construct a block to work on.\n"
|
||||||
"For full specification, see BIPs 22, 23, and 9:\n"
|
"For full specification, see BIPs 22, 23, and 9:\n"
|
||||||
@ -641,8 +655,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("getblocktemplate", "")
|
HelpExampleCli("getblocktemplate", "")
|
||||||
+ HelpExampleRpc("getblocktemplate", "")
|
+ HelpExampleRpc("getblocktemplate", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
|
|
||||||
ChainstateManager& chainman = EnsureChainman(node);
|
ChainstateManager& chainman = EnsureChainman(node);
|
||||||
@ -969,6 +983,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
|||||||
result.pushKV("coinbase_payload", HexStr(pblock->vtx[0]->vExtraPayload));
|
result.pushKV("coinbase_payload", HexStr(pblock->vtx[0]->vExtraPayload));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class submitblock_StateCatcher final : public CValidationInterface
|
class submitblock_StateCatcher final : public CValidationInterface
|
||||||
@ -989,10 +1005,10 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static UniValue submitblock(const JSONRPCRequest& request)
|
static RPCHelpMan submitblock()
|
||||||
{
|
{
|
||||||
// We allow 2 arguments for compliance with BIP22. Argument 2 is ignored.
|
// We allow 2 arguments for compliance with BIP22. Argument 2 is ignored.
|
||||||
RPCHelpMan{"submitblock",
|
return RPCHelpMan{"submitblock",
|
||||||
"\nAttempts to submit new block to network.\n"
|
"\nAttempts to submit new block to network.\n"
|
||||||
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n",
|
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n",
|
||||||
{
|
{
|
||||||
@ -1004,8 +1020,8 @@ static UniValue submitblock(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("submitblock", "\"mydata\"")
|
HelpExampleCli("submitblock", "\"mydata\"")
|
||||||
+ HelpExampleRpc("submitblock", "\"mydata\"")
|
+ HelpExampleRpc("submitblock", "\"mydata\"")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
|
std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
|
||||||
CBlock& block = *blockptr;
|
CBlock& block = *blockptr;
|
||||||
if (!DecodeHexBlk(block, request.params[0].get_str())) {
|
if (!DecodeHexBlk(block, request.params[0].get_str())) {
|
||||||
@ -1043,11 +1059,13 @@ static UniValue submitblock(const JSONRPCRequest& request)
|
|||||||
return "inconclusive";
|
return "inconclusive";
|
||||||
}
|
}
|
||||||
return BIP22ValidationResult(sc->state);
|
return BIP22ValidationResult(sc->state);
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue submitheader(const JSONRPCRequest& request)
|
static RPCHelpMan submitheader()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"submitheader",
|
return RPCHelpMan{"submitheader",
|
||||||
"\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid."
|
"\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid."
|
||||||
"\nThrows when the header is invalid.\n",
|
"\nThrows when the header is invalid.\n",
|
||||||
{
|
{
|
||||||
@ -1059,8 +1077,8 @@ static UniValue submitheader(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("submitheader", "\"aabbcc\"") +
|
HelpExampleCli("submitheader", "\"aabbcc\"") +
|
||||||
HelpExampleRpc("submitheader", "\"aabbcc\"")
|
HelpExampleRpc("submitheader", "\"aabbcc\"")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
CBlockHeader h;
|
CBlockHeader h;
|
||||||
if (!DecodeHexBlockHeader(h, request.params[0].get_str())) {
|
if (!DecodeHexBlockHeader(h, request.params[0].get_str())) {
|
||||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block header decode failed");
|
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block header decode failed");
|
||||||
@ -1080,11 +1098,13 @@ static UniValue submitheader(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());
|
throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());
|
||||||
}
|
}
|
||||||
throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason());
|
throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason());
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue estimatesmartfee(const JSONRPCRequest& request)
|
static RPCHelpMan estimatesmartfee()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"estimatesmartfee",
|
return RPCHelpMan{"estimatesmartfee",
|
||||||
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
|
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
|
||||||
"confirmation within conf_target blocks if possible and return the number of blocks\n"
|
"confirmation within conf_target blocks if possible and return the number of blocks\n"
|
||||||
"for which the estimate is valid.\n",
|
"for which the estimate is valid.\n",
|
||||||
@ -1115,8 +1135,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
|
|||||||
RPCExamples{
|
RPCExamples{
|
||||||
HelpExampleCli("estimatesmartfee", "6")
|
HelpExampleCli("estimatesmartfee", "6")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
|
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
|
||||||
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
||||||
|
|
||||||
@ -1145,11 +1165,13 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
result.pushKV("blocks", feeCalc.returnedTarget);
|
result.pushKV("blocks", feeCalc.returnedTarget);
|
||||||
return result;
|
return result;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue estimaterawfee(const JSONRPCRequest& request)
|
static RPCHelpMan estimaterawfee()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"estimaterawfee",
|
return RPCHelpMan{"estimaterawfee",
|
||||||
"\nWARNING: This interface is unstable and may disappear or change!\n"
|
"\nWARNING: This interface is unstable and may disappear or change!\n"
|
||||||
"\nWARNING: This is an advanced API call that is tightly coupled to the specific\n"
|
"\nWARNING: This is an advanced API call that is tightly coupled to the specific\n"
|
||||||
" implementation of fee estimation. The parameters it can be called with\n"
|
" implementation of fee estimation. The parameters it can be called with\n"
|
||||||
@ -1200,8 +1222,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
|
|||||||
RPCExamples{
|
RPCExamples{
|
||||||
HelpExampleCli("estimaterawfee", "6 0.9")
|
HelpExampleCli("estimaterawfee", "6 0.9")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VNUM}, true);
|
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VNUM}, true);
|
||||||
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
||||||
|
|
||||||
@ -1263,6 +1285,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
|
|||||||
result.pushKV(StringForFeeEstimateHorizon(horizon), horizon_result);
|
result.pushKV(StringForFeeEstimateHorizon(horizon), horizon_result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterMiningRPCCommands(CRPCTable &t)
|
void RegisterMiningRPCCommands(CRPCTable &t)
|
||||||
|
@ -291,13 +291,11 @@ CRPCTable::CRPCTable()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
|
void CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
|
||||||
{
|
{
|
||||||
if (IsRPCRunning())
|
CHECK_NONFATAL(!IsRPCRunning()); // Only add commands before rpc is running
|
||||||
return false;
|
|
||||||
|
|
||||||
mapCommands[name].push_back(pcmd);
|
mapCommands[name].push_back(pcmd);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CRPCTable::removeCommand(const std::string& name, const CRPCCommand* pcmd)
|
bool CRPCTable::removeCommand(const std::string& name, const CRPCCommand* pcmd)
|
||||||
|
@ -160,7 +160,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Appends a CRPCCommand to the dispatch table.
|
* Appends a CRPCCommand to the dispatch table.
|
||||||
*
|
*
|
||||||
* Returns false if RPC server is already running (dump concurrency protection).
|
* Precondition: RPC server is not running
|
||||||
*
|
*
|
||||||
* Commands with different method names but the same unique_id will
|
* Commands with different method names but the same unique_id will
|
||||||
* be considered aliases, and only the first registered method name will
|
* be considered aliases, and only the first registered method name will
|
||||||
@ -169,7 +169,7 @@ public:
|
|||||||
* between calls based on method name, and aliased commands can also
|
* between calls based on method name, and aliased commands can also
|
||||||
* register different names, types, and numbers of parameters.
|
* register different names, types, and numbers of parameters.
|
||||||
*/
|
*/
|
||||||
bool appendCommand(const std::string& name, const CRPCCommand* pcmd);
|
void appendCommand(const std::string& name, const CRPCCommand* pcmd);
|
||||||
bool removeCommand(const std::string& name, const CRPCCommand* pcmd);
|
bool removeCommand(const std::string& name, const CRPCCommand* pcmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,9 +68,9 @@ static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue importprivkey(const JSONRPCRequest& request)
|
RPCHelpMan importprivkey()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"importprivkey",
|
return RPCHelpMan{"importprivkey",
|
||||||
"\nAdds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup.\n"
|
"\nAdds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup.\n"
|
||||||
"Hint: use importmulti to import more than one private key.\n"
|
"Hint: use importmulti to import more than one private key.\n"
|
||||||
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
|
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
|
||||||
@ -93,8 +93,8 @@ UniValue importprivkey(const JSONRPCRequest& request)
|
|||||||
"\nAs a JSON-RPC call\n"
|
"\nAs a JSON-RPC call\n"
|
||||||
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")
|
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
@ -156,11 +156,13 @@ UniValue importprivkey(const JSONRPCRequest& request)
|
|||||||
RescanWallet(*pwallet, reserver);
|
RescanWallet(*pwallet, reserver);
|
||||||
}
|
}
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue abortrescan(const JSONRPCRequest& request)
|
RPCHelpMan abortrescan()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"abortrescan",
|
return RPCHelpMan{"abortrescan",
|
||||||
"\nStops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n",
|
"\nStops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n",
|
||||||
{},
|
{},
|
||||||
RPCResult{RPCResult::Type::BOOL, "", "Whether the abort was successful"},
|
RPCResult{RPCResult::Type::BOOL, "", "Whether the abort was successful"},
|
||||||
@ -172,8 +174,8 @@ UniValue abortrescan(const JSONRPCRequest& request)
|
|||||||
"\nAs a JSON-RPC call\n"
|
"\nAs a JSON-RPC call\n"
|
||||||
+ HelpExampleRpc("abortrescan", "")
|
+ HelpExampleRpc("abortrescan", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
@ -181,11 +183,13 @@ UniValue abortrescan(const JSONRPCRequest& request)
|
|||||||
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) return false;
|
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) return false;
|
||||||
pwallet->AbortRescan();
|
pwallet->AbortRescan();
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
UniValue importaddress(const JSONRPCRequest& request)
|
RPCHelpMan importaddress()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"importaddress",
|
return RPCHelpMan{"importaddress",
|
||||||
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
|
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
|
||||||
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
|
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
|
||||||
"may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
|
"may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
|
||||||
@ -208,8 +212,8 @@ UniValue importaddress(const JSONRPCRequest& request)
|
|||||||
"\nAs a JSON-RPC call\n"
|
"\nAs a JSON-RPC call\n"
|
||||||
+ HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false")
|
+ HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
@ -279,11 +283,13 @@ UniValue importaddress(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue importprunedfunds(const JSONRPCRequest& request)
|
RPCHelpMan importprunedfunds()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"importprunedfunds",
|
return RPCHelpMan{"importprunedfunds",
|
||||||
"\nImports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n",
|
"\nImports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n",
|
||||||
{
|
{
|
||||||
{"rawtransaction", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A raw transaction in hex funding an already-existing address in wallet"},
|
{"rawtransaction", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A raw transaction in hex funding an already-existing address in wallet"},
|
||||||
@ -291,8 +297,8 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
|
|||||||
},
|
},
|
||||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||||
RPCExamples{""},
|
RPCExamples{""},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
@ -336,11 +342,13 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No addresses in wallet correspond to included transaction");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No addresses in wallet correspond to included transaction");
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue removeprunedfunds(const JSONRPCRequest& request)
|
RPCHelpMan removeprunedfunds()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"removeprunedfunds",
|
return RPCHelpMan{"removeprunedfunds",
|
||||||
"\nDeletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet balances.\n",
|
"\nDeletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet balances.\n",
|
||||||
{
|
{
|
||||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded id of the transaction you are deleting"},
|
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded id of the transaction you are deleting"},
|
||||||
@ -351,8 +359,8 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
|
|||||||
"\nAs a JSON-RPC call\n"
|
"\nAs a JSON-RPC call\n"
|
||||||
+ HelpExampleRpc("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"")
|
+ HelpExampleRpc("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
@ -373,11 +381,13 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue importpubkey(const JSONRPCRequest& request)
|
RPCHelpMan importpubkey()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"importpubkey",
|
return RPCHelpMan{"importpubkey",
|
||||||
"\nAdds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
|
"\nAdds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
|
||||||
"Hint: use importmulti to import more than one public key.\n"
|
"Hint: use importmulti to import more than one public key.\n"
|
||||||
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
|
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
|
||||||
@ -396,8 +406,8 @@ UniValue importpubkey(const JSONRPCRequest& request)
|
|||||||
"\nAs a JSON-RPC call\n"
|
"\nAs a JSON-RPC call\n"
|
||||||
+ HelpExampleRpc("importpubkey", "\"mypubkey\", \"testing\", false")
|
+ HelpExampleRpc("importpubkey", "\"mypubkey\", \"testing\", false")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
@ -453,12 +463,14 @@ UniValue importpubkey(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UniValue importwallet(const JSONRPCRequest& request)
|
RPCHelpMan importwallet()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"importwallet",
|
return RPCHelpMan{"importwallet",
|
||||||
"\nImports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup to include imported keys.\n"
|
"\nImports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup to include imported keys.\n"
|
||||||
"Note: Use \"getwalletinfo\" to query the scanning progress.\n",
|
"Note: Use \"getwalletinfo\" to query the scanning progress.\n",
|
||||||
{
|
{
|
||||||
@ -473,8 +485,8 @@ UniValue importwallet(const JSONRPCRequest& request)
|
|||||||
"\nImport using the json rpc call\n"
|
"\nImport using the json rpc call\n"
|
||||||
+ HelpExampleRpc("importwallet", "\"test\"")
|
+ HelpExampleRpc("importwallet", "\"test\"")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
@ -613,11 +625,13 @@ UniValue importwallet(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys/scripts to wallet");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys/scripts to wallet");
|
||||||
|
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue importelectrumwallet(const JSONRPCRequest& request)
|
RPCHelpMan importelectrumwallet()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"importelectrumwallet",
|
return RPCHelpMan{"importelectrumwallet",
|
||||||
"\nImports keys from an Electrum wallet export file (.csv or .json)\n",
|
"\nImports keys from an Electrum wallet export file (.csv or .json)\n",
|
||||||
{
|
{
|
||||||
{"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The Electrum wallet export file, should be in csv or json format"},
|
{"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The Electrum wallet export file, should be in csv or json format"},
|
||||||
@ -632,7 +646,8 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
|
|||||||
+ HelpExampleRpc("importelectrumwallet", "\"test.csv\"")
|
+ HelpExampleRpc("importelectrumwallet", "\"test.csv\"")
|
||||||
+ HelpExampleRpc("importelectrumwallet", "\"test.json\"")
|
+ HelpExampleRpc("importelectrumwallet", "\"test.json\"")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
@ -790,11 +805,13 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet");
|
||||||
|
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue dumpprivkey(const JSONRPCRequest& request)
|
RPCHelpMan dumpprivkey()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"dumpprivkey",
|
return RPCHelpMan{"dumpprivkey",
|
||||||
"\nReveals the private key corresponding to 'address'.\n"
|
"\nReveals the private key corresponding to 'address'.\n"
|
||||||
"Then the importprivkey can be used with this output\n",
|
"Then the importprivkey can be used with this output\n",
|
||||||
{
|
{
|
||||||
@ -808,8 +825,8 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
|
|||||||
+ HelpExampleCli("importprivkey", "\"mykey\"")
|
+ HelpExampleCli("importprivkey", "\"mykey\"")
|
||||||
+ HelpExampleRpc("dumpprivkey", "\"myaddress\"")
|
+ HelpExampleRpc("dumpprivkey", "\"myaddress\"")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
const CWallet* const pwallet = wallet.get();
|
const CWallet* const pwallet = wallet.get();
|
||||||
@ -834,11 +851,13 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
|
||||||
}
|
}
|
||||||
return EncodeSecret(vchSecret);
|
return EncodeSecret(vchSecret);
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue dumphdinfo(const JSONRPCRequest& request)
|
RPCHelpMan dumphdinfo()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"dumphdinfo",
|
return RPCHelpMan{"dumphdinfo",
|
||||||
"Returns an object containing sensitive private info about this HD wallet.\n",
|
"Returns an object containing sensitive private info about this HD wallet.\n",
|
||||||
{},
|
{},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
@ -853,8 +872,8 @@ UniValue dumphdinfo(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("dumphdinfo", "")
|
HelpExampleCli("dumphdinfo", "")
|
||||||
+ HelpExampleRpc("dumphdinfo", "")
|
+ HelpExampleRpc("dumphdinfo", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
const CWallet* const pwallet = wallet.get();
|
const CWallet* const pwallet = wallet.get();
|
||||||
@ -881,11 +900,13 @@ UniValue dumphdinfo(const JSONRPCRequest& request)
|
|||||||
obj.pushKV("mnemonicpassphrase", ssMnemonicPassphrase.c_str());
|
obj.pushKV("mnemonicpassphrase", ssMnemonicPassphrase.c_str());
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue dumpwallet(const JSONRPCRequest& request)
|
RPCHelpMan dumpwallet()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"dumpwallet",
|
return RPCHelpMan{"dumpwallet",
|
||||||
"\nDumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n"
|
"\nDumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n"
|
||||||
"Imported scripts are included in the dumpfile too, their corresponding addresses will be added automatically by importwallet.\n"
|
"Imported scripts are included in the dumpfile too, their corresponding addresses will be added automatically by importwallet.\n"
|
||||||
"Note that if your wallet contains keys which are not derived from your HD seed (e.g. imported keys), these are not covered by\n"
|
"Note that if your wallet contains keys which are not derived from your HD seed (e.g. imported keys), these are not covered by\n"
|
||||||
@ -905,8 +926,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("dumpwallet", "\"test\"")
|
HelpExampleCli("dumpwallet", "\"test\"")
|
||||||
+ HelpExampleRpc("dumpwallet", "\"test\"")
|
+ HelpExampleRpc("dumpwallet", "\"test\"")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!pwallet) return NullUniValue;
|
if (!pwallet) return NullUniValue;
|
||||||
|
|
||||||
@ -1056,6 +1077,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
|
|||||||
obj.pushKV("warning", strWarning);
|
obj.pushKV("warning", strWarning);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ImportData
|
struct ImportData
|
||||||
@ -1430,9 +1453,9 @@ static int64_t GetImportTimestamp(const UniValue& data, int64_t now)
|
|||||||
throw JSONRPCError(RPC_TYPE_ERROR, "Missing required timestamp field for key");
|
throw JSONRPCError(RPC_TYPE_ERROR, "Missing required timestamp field for key");
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue importmulti(const JSONRPCRequest& mainRequest)
|
RPCHelpMan importmulti()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"importmulti",
|
return RPCHelpMan{"importmulti",
|
||||||
"\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.\n"
|
"\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.\n"
|
||||||
"If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.\n"
|
"If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.\n"
|
||||||
"Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned.\n"
|
"Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned.\n"
|
||||||
@ -1504,7 +1527,8 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
|||||||
"{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
|
"{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
|
||||||
HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
|
HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
|
||||||
},
|
},
|
||||||
}.Check(mainRequest);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& mainRequest) -> UniValue
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
|
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
|
||||||
@ -1614,6 +1638,8 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
|
static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
|
||||||
@ -1757,8 +1783,8 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue importdescriptors(const JSONRPCRequest& main_request) {
|
RPCHelpMan importdescriptors() {
|
||||||
RPCHelpMan{"importdescriptors",
|
return RPCHelpMan{"importdescriptors",
|
||||||
"\nImport descriptors. This will trigger a rescan of the blockchain based on the earliest timestamp of all descriptors being imported. Requires a new wallet backup.\n"
|
"\nImport descriptors. This will trigger a rescan of the blockchain based on the earliest timestamp of all descriptors being imported. Requires a new wallet backup.\n"
|
||||||
"\nNote: This call can take over an hour to complete if using an early timestamp; during that time, other rpc calls\n"
|
"\nNote: This call can take over an hour to complete if using an early timestamp; during that time, other rpc calls\n"
|
||||||
"may report that the imported keys, addresses or scripts exist but related transactions are still missing.\n",
|
"may report that the imported keys, addresses or scripts exist but related transactions are still missing.\n",
|
||||||
@ -1807,7 +1833,8 @@ UniValue importdescriptors(const JSONRPCRequest& main_request) {
|
|||||||
"{ \"desc\": \"<my desccriptor 2>\", \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
|
"{ \"desc\": \"<my desccriptor 2>\", \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
|
||||||
HelpExampleCli("importdescriptors", "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, \"active\": true, \"range\": [0,100], \"label\": \"<my wallet>\" }]'")
|
HelpExampleCli("importdescriptors", "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, \"active\": true, \"range\": [0,100], \"label\": \"<my wallet>\" }]'")
|
||||||
},
|
},
|
||||||
}.Check(main_request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& main_request) -> UniValue
|
||||||
|
{
|
||||||
|
|
||||||
// Acquire the wallet
|
// Acquire the wallet
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(main_request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(main_request);
|
||||||
@ -1907,6 +1934,8 @@ UniValue importdescriptors(const JSONRPCRequest& main_request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
RPCHelpMan listdescriptors()
|
RPCHelpMan listdescriptors()
|
||||||
|
@ -4153,20 +4153,20 @@ static UniValue send(const JSONRPCRequest& request)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
|
RPCHelpMan abortrescan();
|
||||||
UniValue dumpprivkey(const JSONRPCRequest& request); // in rpcdump.cpp
|
RPCHelpMan dumpprivkey();
|
||||||
UniValue importprivkey(const JSONRPCRequest& request);
|
RPCHelpMan importprivkey();
|
||||||
UniValue importaddress(const JSONRPCRequest& request);
|
RPCHelpMan importaddress();
|
||||||
UniValue importpubkey(const JSONRPCRequest& request);
|
RPCHelpMan importpubkey();
|
||||||
UniValue dumpwallet(const JSONRPCRequest& request);
|
RPCHelpMan dumpwallet();
|
||||||
UniValue importwallet(const JSONRPCRequest& request);
|
RPCHelpMan importwallet();
|
||||||
UniValue importprunedfunds(const JSONRPCRequest& request);
|
RPCHelpMan importprunedfunds();
|
||||||
UniValue removeprunedfunds(const JSONRPCRequest& request);
|
RPCHelpMan removeprunedfunds();
|
||||||
UniValue importmulti(const JSONRPCRequest& request);
|
RPCHelpMan importmulti();
|
||||||
UniValue importdescriptors(const JSONRPCRequest& request);
|
RPCHelpMan importdescriptors();
|
||||||
RPCHelpMan listdescriptors();
|
RPCHelpMan listdescriptors();
|
||||||
UniValue dumphdinfo(const JSONRPCRequest& request);
|
RPCHelpMan dumphdinfo();
|
||||||
UniValue importelectrumwallet(const JSONRPCRequest& request);
|
RPCHelpMan importelectrumwallet();
|
||||||
|
|
||||||
UniValue walletprocesspsbt(const JSONRPCRequest& request)
|
UniValue walletprocesspsbt(const JSONRPCRequest& request)
|
||||||
{
|
{
|
||||||
|
@ -29,9 +29,9 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
extern UniValue importmulti(const JSONRPCRequest& request);
|
RPCHelpMan importmulti();
|
||||||
extern UniValue dumpwallet(const JSONRPCRequest& request);
|
RPCHelpMan dumpwallet();
|
||||||
extern UniValue importwallet(const JSONRPCRequest& request);
|
RPCHelpMan importwallet();
|
||||||
extern UniValue getnewaddress(const JSONRPCRequest& request);
|
extern UniValue getnewaddress(const JSONRPCRequest& request);
|
||||||
extern UniValue getrawchangeaddress(const JSONRPCRequest& request);
|
extern UniValue getrawchangeaddress(const JSONRPCRequest& request);
|
||||||
extern UniValue getaddressinfo(const JSONRPCRequest& request);
|
extern UniValue getaddressinfo(const JSONRPCRequest& request);
|
||||||
@ -234,7 +234,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
|||||||
request.params.setArray();
|
request.params.setArray();
|
||||||
request.params.push_back(keys);
|
request.params.push_back(keys);
|
||||||
|
|
||||||
UniValue response = importmulti(request);
|
UniValue response = importmulti().HandleRequest(request);
|
||||||
BOOST_CHECK_EQUAL(response.write(),
|
BOOST_CHECK_EQUAL(response.write(),
|
||||||
strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Rescan failed for key with creation "
|
strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Rescan failed for key with creation "
|
||||||
"timestamp %d. There was an error reading a block from time %d, which is after or within %d "
|
"timestamp %d. There was an error reading a block from time %d, which is after or within %d "
|
||||||
@ -287,7 +287,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
|||||||
request.params.setArray();
|
request.params.setArray();
|
||||||
request.params.push_back(backup_file);
|
request.params.push_back(backup_file);
|
||||||
|
|
||||||
::dumpwallet(request);
|
::dumpwallet().HandleRequest(request);
|
||||||
RemoveWallet(wallet, std::nullopt);
|
RemoveWallet(wallet, std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
|||||||
request.params.push_back(backup_file);
|
request.params.push_back(backup_file);
|
||||||
AddWallet(wallet);
|
AddWallet(wallet);
|
||||||
wallet->SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
wallet->SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||||
::importwallet(request);
|
::importwallet().HandleRequest(request);
|
||||||
RemoveWallet(wallet, std::nullopt);
|
RemoveWallet(wallet, std::nullopt);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U);
|
BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U);
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
UniValue getzmqnotifications(const JSONRPCRequest& request)
|
static RPCHelpMan getzmqnotifications()
|
||||||
{
|
{
|
||||||
RPCHelpMan{"getzmqnotifications",
|
return RPCHelpMan{"getzmqnotifications",
|
||||||
"\nReturns information about the active ZeroMQ notifications.\n",
|
"\nReturns information about the active ZeroMQ notifications.\n",
|
||||||
{},
|
{},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
@ -33,8 +33,8 @@ UniValue getzmqnotifications(const JSONRPCRequest& request)
|
|||||||
HelpExampleCli("getzmqnotifications", "")
|
HelpExampleCli("getzmqnotifications", "")
|
||||||
+ HelpExampleRpc("getzmqnotifications", "")
|
+ HelpExampleRpc("getzmqnotifications", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
UniValue result(UniValue::VARR);
|
UniValue result(UniValue::VARR);
|
||||||
if (g_zmq_notification_interface != nullptr) {
|
if (g_zmq_notification_interface != nullptr) {
|
||||||
for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
|
for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
|
||||||
@ -47,6 +47,8 @@ UniValue getzmqnotifications(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const CRPCCommand commands[] =
|
const CRPCCommand commands[] =
|
||||||
|
@ -17,7 +17,8 @@ class RPCGenerateTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
message = (
|
message = (
|
||||||
"generate ( nblocks maxtries ) has been replaced by the -generate "
|
"generate\n"
|
||||||
|
"has been replaced by the -generate "
|
||||||
"cli option. Refer to -help for more information."
|
"cli option. Refer to -help for more information."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user