aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgustavonalle <gustavonalle@gmail.com>2018-09-24 16:10:23 +0100
committerMarcoFalke <falke.marco@gmail.com>2018-11-28 15:35:05 -0500
commitbb9069555120474a53caf55027c2bdc1d4cf383c (patch)
tree247163a2cc82c868fccc54334ff7df9b38099e90
parent5150accdd2a7c7f0edf964d56bd7d34b5f740cdc (diff)
[wallet] Ensure wallet is unlocked before signing
Github-Pull: #14310 Rebased-From: db15805668e923c3493d77122d20926496cf6a1a
-rw-r--r--src/wallet/rpcwallet.cpp2
-rwxr-xr-xtest/functional/rpc_signrawtransaction.py9
2 files changed, 11 insertions, 0 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index a3de618059..9ddd21126a 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -3732,6 +3732,8 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
// Sign the transaction
LOCK2(cs_main, pwallet->cs_wallet);
+ EnsureWalletIsUnlocked(pwallet);
+
return SignTransaction(mtx, request.params[1], pwallet, false, request.params[2]);
}
diff --git a/test/functional/rpc_signrawtransaction.py b/test/functional/rpc_signrawtransaction.py
index 035f10e6bc..823892a349 100755
--- a/test/functional/rpc_signrawtransaction.py
+++ b/test/functional/rpc_signrawtransaction.py
@@ -49,6 +49,14 @@ class SignRawTransactionsTest(BitcoinTestFramework):
rawTxSigned2 = self.nodes[0].signrawtransaction(rawTx, inputs, privKeys)
assert_equal(rawTxSigned, rawTxSigned2)
+ def test_with_lock_outputs(self):
+ """Test correct error reporting when trying to sign a locked output"""
+ self.nodes[0].encryptwallet("password")
+ self.restart_node(0)
+ rawTx = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000'
+
+ assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].signrawtransactionwithwallet, rawTx)
+
def script_verification_error_test(self):
"""Create and sign a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script.
@@ -150,6 +158,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
def run_test(self):
self.successful_signing_test()
self.script_verification_error_test()
+ self.test_with_lock_outputs()
if __name__ == '__main__':