mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
wallet, rpc: Disallow importing unused() to wallets without privkeys
This commit is contained in:
parent
5c4a0a3a5c
commit
17de9e6f63
2 changed files with 18 additions and 0 deletions
|
@ -1575,6 +1575,9 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
|
|||
|
||||
// If this is an unused(KEY) descriptor, check that the wallet doesn't already have other descriptors with this key
|
||||
if (!parsed_desc->HasScripts()) {
|
||||
if (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import unused() to wallet without private keys enabled");
|
||||
}
|
||||
// Unused descriptors must contain a single key.
|
||||
// Earlier checks will have enforced that this key is either a private key when private keys are enabled,
|
||||
// or that this key is a public key when private keys are disabled.
|
||||
|
|
|
@ -100,6 +100,20 @@ class ImportDescriptorsTest(BitcoinTestFramework):
|
|||
wallet=wallet)
|
||||
wallet.unloadwallet()
|
||||
|
||||
def test_import_unused_noprivs(self):
|
||||
self.log.info("Test import of unused(KEY) to wallet without privkeys")
|
||||
self.nodes[0].createwallet(wallet_name="import_unused_noprivs", disable_private_keys=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc("import_unused_noprivs")
|
||||
|
||||
xpub = "tpubD6NzVbkrYhZ4YNXVQbNhMK1WqguFsUXceaVJKbmno2aZ3B6QfbMeraaYvnBSGpV3vxLyTTK9DYT1yoEck4XUScMzXoQ2U2oSmE2JyMedq3H"
|
||||
self.test_importdesc({"timestamp": "now", "desc": descsum_create(f"unused({xpub})")},
|
||||
success=False,
|
||||
error_code=-4,
|
||||
error_message="Cannot import unused() to wallet without private keys enabled",
|
||||
wallet=wallet)
|
||||
wallet.unloadwallet()
|
||||
|
||||
|
||||
def run_test(self):
|
||||
self.log.info('Setting up wallets')
|
||||
self.nodes[0].createwallet(wallet_name='w0', disable_private_keys=False, descriptors=True)
|
||||
|
@ -795,6 +809,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
|
|||
|
||||
self.test_import_unused_key()
|
||||
self.test_import_unused_key_existing()
|
||||
self.test_import_unused_noprivs()
|
||||
|
||||
if __name__ == '__main__':
|
||||
ImportDescriptorsTest(__file__).main()
|
||||
|
|
Loading…
Reference in a new issue