Skip to content

Commit 538be42

Browse files
committed
wallet: fix importdescriptor silent fail
1 parent 711ddce commit 538be42

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/wallet/rpcdump.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,9 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
15221522
// Need to ExpandPrivate to check if private keys are available for all pubkeys
15231523
FlatSigningProvider expand_keys;
15241524
std::vector<CScript> scripts;
1525-
parsed_desc->Expand(0, keys, scripts, expand_keys);
1525+
if (!parsed_desc->Expand(0, keys, scripts, expand_keys)) {
1526+
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot expand descriptor. Probably because of hardened derivations without private keys provided");
1527+
}
15261528
parsed_desc->ExpandPrivate(0, keys, expand_keys);
15271529

15281530
// Check if all private keys are provided

src/wallet/wallet.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4555,7 +4555,10 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
45554555
}
45564556

45574557
// Top up key pool, the manager will generate new scriptPubKeys internally
4558-
new_spk_man->TopUp();
4558+
if (!new_spk_man->TopUp()) {
4559+
WalletLogPrintf("Could not top up scriptPubKeys\n");
4560+
return nullptr;
4561+
}
45594562

45604563
// Apply the label if necessary
45614564
// Note: we disable labels for ranged descriptors

test/functional/wallet_importdescriptors.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ def run_test(self):
207207
success=False,
208208
error_code=-4,
209209
error_message='Cannot import private keys to a wallet with private keys disabled')
210+
211+
self.log.info("Should not import a descriptor with hardened derivations when private keys are disabled")
212+
self.test_importdesc({"desc": descsum_create("wpkh(" + xpub + "/1h/*)"),
213+
"timestamp": "now",
214+
"range": 1},
215+
success=False,
216+
error_code=-4,
217+
error_message='Cannot expand descriptor. Probably because of hardened derivations without private keys provided')
218+
210219
for address in addresses:
211220
test_address(w1,
212221
address,

0 commit comments

Comments
 (0)