mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-11 07:09:29 +02:00
wallet, rpc: add listdescriptors private option
This commit is contained in:
@@ -1755,8 +1755,10 @@ RPCHelpMan listdescriptors()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
"listdescriptors",
|
||||
"\nList descriptors imported into a descriptor-enabled wallet.",
|
||||
{},
|
||||
"\nList descriptors imported into a descriptor-enabled wallet.\n",
|
||||
{
|
||||
{"private", RPCArg::Type::BOOL, RPCArg::Default{false}, "Show private descriptors."}
|
||||
},
|
||||
RPCResult{RPCResult::Type::OBJ, "", "", {
|
||||
{RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
|
||||
{RPCResult::Type::ARR, "descriptors", "Array of descriptor objects",
|
||||
@@ -1776,6 +1778,7 @@ RPCHelpMan listdescriptors()
|
||||
}},
|
||||
RPCExamples{
|
||||
HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
|
||||
+ HelpExampleCli("listdescriptors", "true") + HelpExampleRpc("listdescriptors", "true")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
@@ -1786,6 +1789,11 @@ RPCHelpMan listdescriptors()
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "listdescriptors is not available for non-descriptor wallets");
|
||||
}
|
||||
|
||||
const bool priv = !request.params[0].isNull() && request.params[0].get_bool();
|
||||
if (priv) {
|
||||
EnsureWalletIsUnlocked(*wallet);
|
||||
}
|
||||
|
||||
LOCK(wallet->cs_wallet);
|
||||
|
||||
UniValue descriptors(UniValue::VARR);
|
||||
@@ -1799,8 +1807,9 @@ RPCHelpMan listdescriptors()
|
||||
LOCK(desc_spk_man->cs_desc_man);
|
||||
const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
|
||||
std::string descriptor;
|
||||
if (!desc_spk_man->GetDescriptorString(descriptor)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get normalized descriptor string.");
|
||||
|
||||
if (!desc_spk_man->GetDescriptorString(descriptor, priv)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get descriptor string.");
|
||||
}
|
||||
spk.pushKV("desc", descriptor);
|
||||
spk.pushKV("timestamp", wallet_descriptor.creation_time);
|
||||
|
||||
Reference in New Issue
Block a user