Skip to content

Commit 17de9e6

Browse files
committed
wallet, rpc: Disallow importing unused() to wallets without privkeys
1 parent 5c4a0a3 commit 17de9e6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/wallet/rpc/backup.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,9 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
15751575

15761576
// If this is an unused(KEY) descriptor, check that the wallet doesn't already have other descriptors with this key
15771577
if (!parsed_desc->HasScripts()) {
1578+
if (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
1579+
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import unused() to wallet without private keys enabled");
1580+
}
15781581
// Unused descriptors must contain a single key.
15791582
// Earlier checks will have enforced that this key is either a private key when private keys are enabled,
15801583
// or that this key is a public key when private keys are disabled.

test/functional/wallet_importdescriptors.py

+15
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ def test_import_unused_key_existing(self):
100100
wallet=wallet)
101101
wallet.unloadwallet()
102102

103+
def test_import_unused_noprivs(self):
104+
self.log.info("Test import of unused(KEY) to wallet without privkeys")
105+
self.nodes[0].createwallet(wallet_name="import_unused_noprivs", disable_private_keys=True)
106+
wallet = self.nodes[0].get_wallet_rpc("import_unused_noprivs")
107+
108+
xpub = "tpubD6NzVbkrYhZ4YNXVQbNhMK1WqguFsUXceaVJKbmno2aZ3B6QfbMeraaYvnBSGpV3vxLyTTK9DYT1yoEck4XUScMzXoQ2U2oSmE2JyMedq3H"
109+
self.test_importdesc({"timestamp": "now", "desc": descsum_create(f"unused({xpub})")},
110+
success=False,
111+
error_code=-4,
112+
error_message="Cannot import unused() to wallet without private keys enabled",
113+
wallet=wallet)
114+
wallet.unloadwallet()
115+
116+
103117
def run_test(self):
104118
self.log.info('Setting up wallets')
105119
self.nodes[0].createwallet(wallet_name='w0', disable_private_keys=False, descriptors=True)
@@ -795,6 +809,7 @@ def run_test(self):
795809

796810
self.test_import_unused_key()
797811
self.test_import_unused_key_existing()
812+
self.test_import_unused_noprivs()
798813

799814
if __name__ == '__main__':
800815
ImportDescriptorsTest(__file__).main()

0 commit comments

Comments
 (0)