Skip to content

Commit 0a9e79a

Browse files
achow101vijaydasmp
authored andcommitted
Merge bitcoin#26116: rpc: Allow importmulti watchonly imports with locked wallet
2c03465 test: Test watchonly imports with passphrase-locked wallet (Aurèle Oulès) 1fcf9e6 rpc: Allow importmulti watchonly imports with locked wallet (Aurèle Oulès) Pull request description: Allows watch-only imports on locked wallets with `importmulti`. Also adds a test. Fixes bitcoin#17867. ACKs for top commit: achow101: ACK 2c03465 kristapsk: re-ACK 2c03465 theStack: re-ACK 2c03465 Tree-SHA512: 9978d6e59a230c0d160efd312c671cf59458797387d6622b6bf5c9e0681c1fcfebedb3d834fa9314dc5a1eda97e3295696352eacbeab9b43a46b942990087035
1 parent da8a475 commit 0a9e79a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/wallet/rpcdump.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,18 @@ RPCHelpMan importmulti()
15741574
UniValue response(UniValue::VARR);
15751575
{
15761576
LOCK(pwallet->cs_wallet);
1577-
EnsureWalletIsUnlocked(*pwallet);
1577+
1578+
// Check all requests are watchonly
1579+
bool is_watchonly{true};
1580+
for (size_t i = 0; i < requests.size(); ++i) {
1581+
const UniValue& request = requests[i];
1582+
if (!request.exists("watchonly") || !request["watchonly"].get_bool()) {
1583+
is_watchonly = false;
1584+
break;
1585+
}
1586+
}
1587+
// Wallet does not need to be unlocked if all requests are watchonly
1588+
if (!is_watchonly) EnsureWalletIsUnlocked(wallet);
15781589

15791590
// Verify all timestamps are present before importing any keys.
15801591
CHECK_NONFATAL(pwallet->chain().findBlock(pwallet->GetLastBlockHash(), FoundBlock().time(nLowestTimestamp).mtpTime(now)));

test/functional/wallet_importmulti.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,25 @@ def run_test(self):
709709
addr = wrpc.getnewaddress('')
710710
assert_equal(addr, addresses[i])
711711

712+
# Create wallet with passphrase
713+
self.log.info('Test watchonly imports on a wallet with a passphrase, without unlocking')
714+
self.nodes[1].createwallet(wallet_name='w1', blank=True, passphrase='pass')
715+
wrpc = self.nodes[1].get_wallet_rpc('w1')
716+
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first.",
717+
wrpc.importmulti, [{
718+
'desc': descsum_create('wpkh(' + pub1 + ')'),
719+
"timestamp": "now",
720+
}])
721+
722+
result = wrpc.importmulti(
723+
[{
724+
'desc': descsum_create('wpkh(' + pub1 + ')'),
725+
"timestamp": "now",
726+
"watchonly": True,
727+
}]
728+
)
729+
assert result[0]['success']
730+
712731

713732
if __name__ == '__main__':
714733
ImportMultiTest().main()

0 commit comments

Comments
 (0)