Skip to content

Commit b23cefb

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

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
260260

261261
// If this is an unused(KEY) descriptor, check that the wallet doesn't already have other descriptors with this key
262262
if (!parsed_desc->HasScripts()) {
263+
if (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
264+
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import unused() to wallet without private keys enabled");
265+
}
263266
// Unused descriptors must contain a single key.
264267
// Earlier checks will have enforced that this key is either a private key when private keys are enabled,
265268
// or that this key is a public key when private keys are disabled.

test/functional/wallet_importdescriptors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ def test_import_unused_key_existing(self):
102102
wallet=wallet)
103103
wallet.unloadwallet()
104104

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

812826
self.test_import_unused_key()
813827
self.test_import_unused_key_existing()
828+
self.test_import_unused_noprivs()
814829

815830
if __name__ == '__main__':
816831
ImportDescriptorsTest(__file__).main()

0 commit comments

Comments
 (0)