mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-17 17:02:43 +00:00
walletrpc: reject listdes with priv key on w-only wallets
This commit is contained in:
parent
9e5e9824f1
commit
ed945a6854
@ -17,6 +17,7 @@
|
||||
#include <sync.h>
|
||||
#include <uint256.h>
|
||||
#include <util/bip32.h>
|
||||
#include <util/check.h>
|
||||
#include <util/fs.h>
|
||||
#include <util/time.h>
|
||||
#include <util/translation.h>
|
||||
@ -493,6 +494,9 @@ RPCHelpMan listdescriptors()
|
||||
if (!wallet) return UniValue::VNULL;
|
||||
|
||||
const bool priv = !request.params[0].isNull() && request.params[0].get_bool();
|
||||
if (wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && priv) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get private descriptor string for watch-only wallets");
|
||||
}
|
||||
if (priv) {
|
||||
EnsureWalletIsUnlocked(*wallet);
|
||||
}
|
||||
@ -519,9 +523,7 @@ 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, priv)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get descriptor string.");
|
||||
}
|
||||
CHECK_NONFATAL(desc_spk_man->GetDescriptorString(descriptor, priv));
|
||||
const bool is_range = wallet_descriptor.descriptor->IsRange();
|
||||
wallet_descriptors.push_back({
|
||||
descriptor,
|
||||
|
||||
@ -107,7 +107,7 @@ class ListDescriptorsTest(BitcoinTestFramework):
|
||||
'desc': descsum_create('wpkh(' + xpub_acc + ')'),
|
||||
'timestamp': TIME_GENESIS_BLOCK,
|
||||
}])
|
||||
assert_raises_rpc_error(-4, 'Can\'t get descriptor string', watch_only_wallet.listdescriptors, True)
|
||||
assert_raises_rpc_error(-4, 'Can\'t get private descriptor string for watch-only wallets', watch_only_wallet.listdescriptors, True)
|
||||
|
||||
self.log.info('Test non-active non-range combo descriptor')
|
||||
node.createwallet(wallet_name='w4', blank=True)
|
||||
@ -122,7 +122,7 @@ class ListDescriptorsTest(BitcoinTestFramework):
|
||||
{'active': False,
|
||||
'desc': 'combo(0227d85ba011276cf25b51df6a188b75e604b38770a462b2d0e9fb2fc839ef5d3f)#np574htj',
|
||||
'timestamp': TIME_GENESIS_BLOCK},
|
||||
]
|
||||
],
|
||||
}
|
||||
assert_equal(expected, wallet.listdescriptors())
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user