Skip to content

Commit e060673

Browse files
author
MarcoFalke
committed
Merge #16250: signrawtransactionwithkey: report error when missing redeemScript/witnessScript
0117459 signrawtransactionwithkey: report error when missing redeemScript/witnessScript param (Anthony Towns) Pull request description: Adding support for "witnessScript" as an alternative to "redeemScript" when using "signrawtransactionwithkey" meant that the `RPCTypeCheckObj()` call in `SignTransaction` can't error out just because either parameter is missing -- it's only a problem if both are missing, which isn't a state `RPCTypeCheckObj()` tests for. This results in the regression described in #16249. This patch adds some code to test for this case and give a similar error, namely: error code: -8 error message: Missing redeemScript/witnessScript Fixes: #16249 ACKs for top commit: meshcollider: utACK bitcoin/bitcoin@0117459 promag: ACK 0117459. Could also write test without `dict`/`del`: Tree-SHA512: cf51346b7dea551b7f18f2a93c2a336a293b2535c62c03a5263cd2be8c58cf0cc302891da659c167e88ad1a68a756472c3c07e99f71627c61d32886fc5a3a353
2 parents 4db2f8c + 0117459 commit e060673

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/rpc/rawtransaction_util.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival
221221
// Automatically also add the P2WSH wrapped version of the script (to deal with P2SH-P2WSH).
222222
keystore->AddCScript(GetScriptForWitness(witnessScript));
223223
}
224+
if (rs.isNull() && ws.isNull()) {
225+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing redeemScript/witnessScript");
226+
}
224227
}
225228
}
226229
}

test/functional/rpc_createmultisig.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def do_multisig(self):
129129
outval = value - decimal.Decimal("0.00001000")
130130
rawtx = node2.createrawtransaction([{"txid": txid, "vout": vout}], [{self.final: outval}])
131131

132+
prevtx_err = dict(prevtxs[0])
133+
del prevtx_err["redeemScript"]
134+
135+
assert_raises_rpc_error(-8, "Missing redeemScript/witnessScript", node2.signrawtransactionwithkey, rawtx, self.priv[0:self.nsigs-1], [prevtx_err])
136+
132137
rawtx2 = node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs - 1], prevtxs)
133138
rawtx3 = node2.signrawtransactionwithkey(rawtx2["hex"], [self.priv[-1]], prevtxs)
134139

0 commit comments

Comments
 (0)