mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge #21302: wallet: createwallet examples for descriptor wallets
5039e0e55atest: HelpExampleCliNamed and HelpExampleRpcNamed (Ivan Metlushko)591735ef0brpc: Add HelpExampleCliNamed and use it for `createwallet` doc (Wladimir J. van der Laan)5d5a90e819rpc: Add HelpExampleRpcNamed (Ivan Metlushko) Pull request description: Rationale: make descriptor wallets more visible and just a bit easier to setup `bitcoin-cli help createwallet` **Before**: ``` Examples: > bitcoin-cli createwallet "testwallet" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "createwallet", "params": ["testwallet"]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/ ``` **After** ``` Examples: > bitcoin-cli createwallet "testwallet" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "createwallet", "params": ["testwallet"]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/ > bitcoin-cli createwallet "descriptors" false false "" true true true > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "createwallet", "params": ["descriptors", false, false, "", true, true, true]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/ ``` ACKs for top commit: laanwj: Tested ACK5039e0e55aTree-SHA512: d37210e6ce639addee881377092d8f6fb2a537a60a259c561899e24cf68a0254d7ff45a213573c938f626677e46770cd21113aae5974f26c66b9a2e137699c14
This commit is contained in:
@@ -113,17 +113,80 @@ std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey)
|
||||
return ParseHexV(find_value(o, strKey), strKey);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* Quote an argument for shell.
|
||||
*
|
||||
* @note This is intended for help, not for security-sensitive purposes.
|
||||
*/
|
||||
std::string ShellQuote(const std::string& s)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(s.size() * 2);
|
||||
for (const char ch: s) {
|
||||
if (ch == '\'') {
|
||||
result += "'\''";
|
||||
} else {
|
||||
result += ch;
|
||||
}
|
||||
}
|
||||
return "'" + result + "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Shell-quotes the argument if it needs quoting, else returns it literally, to save typing.
|
||||
*
|
||||
* @note This is intended for help, not for security-sensitive purposes.
|
||||
*/
|
||||
std::string ShellQuoteIfNeeded(const std::string& s)
|
||||
{
|
||||
for (const char ch: s) {
|
||||
if (ch == ' ' || ch == '\'' || ch == '"') {
|
||||
return ShellQuote(s);
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string HelpExampleCli(const std::string& methodname, const std::string& args)
|
||||
{
|
||||
return "> bitcoin-cli " + methodname + " " + args + "\n";
|
||||
}
|
||||
|
||||
std::string HelpExampleCliNamed(const std::string& methodname, const RPCArgList& args)
|
||||
{
|
||||
std::string result = "> bitcoin-cli -named " + methodname;
|
||||
for (const auto& argpair: args) {
|
||||
const auto& value = argpair.second.isStr()
|
||||
? argpair.second.get_str()
|
||||
: argpair.second.write();
|
||||
result += " " + argpair.first + "=" + ShellQuoteIfNeeded(value);
|
||||
}
|
||||
result += "\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string HelpExampleRpc(const std::string& methodname, const std::string& args)
|
||||
{
|
||||
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", "
|
||||
"\"method\": \"" + methodname + "\", \"params\": [" + args + "]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
|
||||
}
|
||||
|
||||
std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args)
|
||||
{
|
||||
UniValue params(UniValue::VOBJ);
|
||||
for (const auto& param: args) {
|
||||
params.pushKV(param.first, param.second);
|
||||
}
|
||||
|
||||
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", "
|
||||
"\"method\": \"" + methodname + "\", \"params\": " + params.write() + "}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
|
||||
}
|
||||
|
||||
// Converts a hex string to a public key if possible
|
||||
CPubKey HexToPubKey(const std::string& hex_in)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user