Skip to content

Commit 745eb67

Browse files
NicolasDoriersipa
authored andcommitted
[RPC] signrawtransaction can sign P2WSH
1 parent f4691ab commit 745eb67

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
454454

455455
// if redeemScript given and private keys given,
456456
// add redeemScript to the tempKeystore so it can be signed:
457-
if (fGivenKeys && scriptPubKey.IsPayToScriptHash() &&
457+
if (fGivenKeys && (scriptPubKey.IsPayToScriptHash() || scriptPubKey.IsPayToWitnessScriptHash()) &&
458458
prevOut.exists("redeemScript")) {
459459
UniValue v = prevOut["redeemScript"];
460460
vector<unsigned char> rsData(ParseHexUV(v, "redeemScript"));

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
592592
" \"txid\":\"id\", (string, required) The transaction id\n"
593593
" \"vout\":n, (numeric, required) The output number\n"
594594
" \"scriptPubKey\": \"hex\", (string, required) script key\n"
595-
" \"redeemScript\": \"hex\", (string, required for P2SH) redeem script\n"
595+
" \"redeemScript\": \"hex\", (string, required for P2SH or P2WSH) redeem script\n"
596596
" \"amount\": value (numeric, required) The amount spent\n"
597597
" }\n"
598598
" ,...\n"
@@ -744,7 +744,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
744744

745745
// if redeemScript given and not using the local wallet (private keys
746746
// given), add redeemScript to the tempKeystore so it can be signed:
747-
if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) {
747+
if (fGivenKeys && (scriptPubKey.IsPayToScriptHash() || scriptPubKey.IsPayToWitnessScriptHash())) {
748748
RPCTypeCheckObj(prevOut,
749749
{
750750
{"txid", UniValueType(UniValue::VSTR)},

src/script/script.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ bool CScript::IsPayToScriptHash() const
210210
(*this)[22] == OP_EQUAL);
211211
}
212212

213+
bool CScript::IsPayToWitnessScriptHash() const
214+
{
215+
// Extra-fast test for pay-to-witness-script-hash CScripts:
216+
return (this->size() == 34 &&
217+
(*this)[0] == OP_0 &&
218+
(*this)[1] == 0x20);
219+
}
220+
213221
// A witness program is any valid CScript that consists of a 1-byte push opcode
214222
// followed by a data push between 2 and 40 bytes.
215223
bool CScript::IsWitnessProgram(int& version, std::vector<unsigned char>& program) const

src/script/script.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ class CScript : public CScriptBase
621621
unsigned int GetSigOpCount(const CScript& scriptSig) const;
622622

623623
bool IsPayToScriptHash() const;
624+
bool IsPayToWitnessScriptHash() const;
624625
bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
625626

626627
/** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */

0 commit comments

Comments
 (0)