Skip to content

Commit fc40175

Browse files
committed
Merge bitcoin/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 #17867. ACKs for top commit: achow101: ACK 2c03465 kristapsk: re-ACK 2c03465 theStack: re-ACK 2c03465 Tree-SHA512: 9978d6e59a230c0d160efd312c671cf59458797387d6622b6bf5c9e0681c1fcfebedb3d834fa9314dc5a1eda97e3295696352eacbeab9b43a46b942990087035
2 parents 5b6f0f3 + 2c03465 commit fc40175

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
@@ -1363,7 +1363,18 @@ RPCHelpMan importmulti()
13631363
UniValue response(UniValue::VARR);
13641364
{
13651365
LOCK(pwallet->cs_wallet);
1366-
EnsureWalletIsUnlocked(*pwallet);
1366+
1367+
// Check all requests are watchonly
1368+
bool is_watchonly{true};
1369+
for (size_t i = 0; i < requests.size(); ++i) {
1370+
const UniValue& request = requests[i];
1371+
if (!request.exists("watchonly") || !request["watchonly"].get_bool()) {
1372+
is_watchonly = false;
1373+
break;
1374+
}
1375+
}
1376+
// Wallet does not need to be unlocked if all requests are watchonly
1377+
if (!is_watchonly) EnsureWalletIsUnlocked(wallet);
13671378

13681379
// Verify all timestamps are present before importing any keys.
13691380
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
@@ -874,6 +874,25 @@ def run_test(self):
874874
addr = wrpc.getnewaddress('', 'bech32')
875875
assert_equal(addr, addresses[i])
876876

877+
# Create wallet with passphrase
878+
self.log.info('Test watchonly imports on a wallet with a passphrase, without unlocking')
879+
self.nodes[1].createwallet(wallet_name='w1', blank=True, passphrase='pass')
880+
wrpc = self.nodes[1].get_wallet_rpc('w1')
881+
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first.",
882+
wrpc.importmulti, [{
883+
'desc': descsum_create('wpkh(' + pub1 + ')'),
884+
"timestamp": "now",
885+
}])
886+
887+
result = wrpc.importmulti(
888+
[{
889+
'desc': descsum_create('wpkh(' + pub1 + ')'),
890+
"timestamp": "now",
891+
"watchonly": True,
892+
}]
893+
)
894+
assert result[0]['success']
895+
877896

878897
if __name__ == '__main__':
879898
ImportMultiTest().main()

0 commit comments

Comments
 (0)