File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1363,7 +1363,18 @@ RPCHelpMan importmulti()
1363
1363
UniValue response (UniValue::VARR);
1364
1364
{
1365
1365
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);
1367
1378
1368
1379
// Verify all timestamps are present before importing any keys.
1369
1380
CHECK_NONFATAL (pwallet->chain ().findBlock (pwallet->GetLastBlockHash (), FoundBlock ().time (nLowestTimestamp).mtpTime (now)));
Original file line number Diff line number Diff line change @@ -874,6 +874,25 @@ def run_test(self):
874
874
addr = wrpc .getnewaddress ('' , 'bech32' )
875
875
assert_equal (addr , addresses [i ])
876
876
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
+
877
896
878
897
if __name__ == '__main__' :
879
898
ImportMultiTest ().main ()
You can’t perform that action at this time.
0 commit comments