Skip to content

Commit db15805

Browse files
author
gustavonalle
committed
[wallet] Ensure wallet is unlocked before signing
1 parent 985d28c commit db15805

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,8 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
31163116

31173117
// Sign the transaction
31183118
LOCK2(cs_main, pwallet->cs_wallet);
3119+
EnsureWalletIsUnlocked(pwallet);
3120+
31193121
return SignTransaction(mtx, request.params[1], pwallet, false, request.params[2]);
31203122
}
31213123

test/functional/rpc_signrawtransaction.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def successful_signing_test(self):
4545
# 2) No script verification error occurred
4646
assert 'errors' not in rawTxSigned
4747

48+
def test_with_lock_outputs(self):
49+
"""Test correct error reporting when trying to sign a locked output"""
50+
self.nodes[0].encryptwallet("password")
51+
self.restart_node(0)
52+
rawTx = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000'
53+
54+
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].signrawtransactionwithwallet, rawTx)
55+
4856
def script_verification_error_test(self):
4957
"""Create and sign a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script.
5058
@@ -138,6 +146,7 @@ def script_verification_error_test(self):
138146
def run_test(self):
139147
self.successful_signing_test()
140148
self.script_verification_error_test()
149+
self.test_with_lock_outputs()
141150

142151

143152
if __name__ == '__main__':

0 commit comments

Comments
 (0)