Skip to content

Commit 5759d18

Browse files
achow101knst
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 f650f65 commit 5759d18

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,18 @@ RPCHelpMan importmulti()
15821582
UniValue response(UniValue::VARR);
15831583
{
15841584
LOCK(pwallet->cs_wallet);
1585-
EnsureWalletIsUnlocked(*pwallet);
1585+
1586+
// Check all requests are watchonly
1587+
bool is_watchonly{true};
1588+
for (size_t i = 0; i < requests.size(); ++i) {
1589+
const UniValue& request = requests[i];
1590+
if (!request.exists("watchonly") || !request["watchonly"].get_bool()) {
1591+
is_watchonly = false;
1592+
break;
1593+
}
1594+
}
1595+
// Wallet does not need to be unlocked if all requests are watchonly
1596+
if (!is_watchonly) EnsureWalletIsUnlocked(wallet);
15861597

15871598
// Verify all timestamps are present before importing any keys.
15881599
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
@@ -708,6 +708,25 @@ def run_test(self):
708708
addr = wrpc.getnewaddress('')
709709
assert_equal(addr, addresses[i])
710710

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

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

0 commit comments

Comments
 (0)