Browse Source

[RPC] signrawtransaction can sign P2WSH

0.13
NicolasDorier 9 years ago committed by Pieter Wuille
parent
commit
745eb678ef
  1. 2
      src/bitcoin-tx.cpp
  2. 4
      src/rpc/rawtransaction.cpp
  3. 8
      src/script/script.cpp
  4. 1
      src/script/script.h

2
src/bitcoin-tx.cpp

@ -454,7 +454,7 @@ static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
// if redeemScript given and private keys given, // if redeemScript given and private keys given,
// add redeemScript to the tempKeystore so it can be signed: // add redeemScript to the tempKeystore so it can be signed:
if (fGivenKeys && scriptPubKey.IsPayToScriptHash() && if (fGivenKeys && (scriptPubKey.IsPayToScriptHash() || scriptPubKey.IsPayToWitnessScriptHash()) &&
prevOut.exists("redeemScript")) { prevOut.exists("redeemScript")) {
UniValue v = prevOut["redeemScript"]; UniValue v = prevOut["redeemScript"];
vector<unsigned char> rsData(ParseHexUV(v, "redeemScript")); vector<unsigned char> rsData(ParseHexUV(v, "redeemScript"));

4
src/rpc/rawtransaction.cpp

@ -592,7 +592,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
" \"txid\":\"id\", (string, required) The transaction id\n" " \"txid\":\"id\", (string, required) The transaction id\n"
" \"vout\":n, (numeric, required) The output number\n" " \"vout\":n, (numeric, required) The output number\n"
" \"scriptPubKey\": \"hex\", (string, required) script key\n" " \"scriptPubKey\": \"hex\", (string, required) script key\n"
" \"redeemScript\": \"hex\", (string, required for P2SH) redeem script\n" " \"redeemScript\": \"hex\", (string, required for P2SH or P2WSH) redeem script\n"
" \"amount\": value (numeric, required) The amount spent\n" " \"amount\": value (numeric, required) The amount spent\n"
" }\n" " }\n"
" ,...\n" " ,...\n"
@ -744,7 +744,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
// if redeemScript given and not using the local wallet (private keys // if redeemScript given and not using the local wallet (private keys
// given), add redeemScript to the tempKeystore so it can be signed: // given), add redeemScript to the tempKeystore so it can be signed:
if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) { if (fGivenKeys && (scriptPubKey.IsPayToScriptHash() || scriptPubKey.IsPayToWitnessScriptHash())) {
RPCTypeCheckObj(prevOut, RPCTypeCheckObj(prevOut,
{ {
{"txid", UniValueType(UniValue::VSTR)}, {"txid", UniValueType(UniValue::VSTR)},

8
src/script/script.cpp

@ -210,6 +210,14 @@ bool CScript::IsPayToScriptHash() const
(*this)[22] == OP_EQUAL); (*this)[22] == OP_EQUAL);
} }
bool CScript::IsPayToWitnessScriptHash() const
{
// Extra-fast test for pay-to-witness-script-hash CScripts:
return (this->size() == 34 &&
(*this)[0] == OP_0 &&
(*this)[1] == 0x20);
}
// A witness program is any valid CScript that consists of a 1-byte push opcode // A witness program is any valid CScript that consists of a 1-byte push opcode
// followed by a data push between 2 and 40 bytes. // followed by a data push between 2 and 40 bytes.
bool CScript::IsWitnessProgram(int& version, std::vector<unsigned char>& program) const bool CScript::IsWitnessProgram(int& version, std::vector<unsigned char>& program) const

1
src/script/script.h

@ -621,6 +621,7 @@ public:
unsigned int GetSigOpCount(const CScript& scriptSig) const; unsigned int GetSigOpCount(const CScript& scriptSig) const;
bool IsPayToScriptHash() const; bool IsPayToScriptHash() const;
bool IsPayToWitnessScriptHash() const;
bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const; bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
/** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */ /** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */

Loading…
Cancel
Save