Skip to content

Commit 0b24db2

Browse files
committed
Merge petertodd#261: Fix misuse of the term redeemScript in p2wsh example
d05bc12 also fix a comment about redeemScript for p2wsh (Bryan Bishop) e311d27 fix misuse of the term redeemScript in p2wsh example (Bryan Bishop) Pull request description: redeemScript should refer to the value that needs to be revealed in order to spend the utxo. In the previous version of the example, redeemScript was the scriptPubKey which isn't right. Top commit has no ACKs. Tree-SHA512: 20f442ef2bffb2d1c017662545e43d8493e8da4c2161572f6382d189e059328e84d1def0980ac46d5071a2a8d09ca8578921c7c36e6852a63ab56cf568f1d0ef
2 parents 03f2ce2 + d05bc12 commit 0b24db2

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

examples/spend-p2wsh-txout.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333

3434
# Create a witnessScript and corresponding redeemScript. Similar to a scriptPubKey
3535
# the redeemScript must be satisfied for the funds to be spent.
36-
txin_witnessScript = CScript([seckey.pub, OP_CHECKSIG])
37-
txin_scriptHash = hashlib.sha256(txin_witnessScript).digest()
38-
txin_redeemScript = CScript([OP_0, txin_scriptHash])
36+
txin_redeemScript = CScript([seckey.pub, OP_CHECKSIG])
37+
txin_scriptHash = hashlib.sha256(txin_redeemScript).digest()
38+
txin_scriptPubKey = CScript([OP_0, txin_scriptHash])
3939

4040

4141
# Convert the P2WSH scriptPubKey to a base58 Bitcoin address and print it.
4242
# You'll need to send some funds to it to create a txout to spend.
43-
txin_p2wsh_address = P2WSHBitcoinAddress.from_scriptPubKey(txin_redeemScript)
43+
txin_p2wsh_address = P2WSHBitcoinAddress.from_scriptPubKey(txin_scriptPubKey)
4444
print('Pay to:', str(txin_p2wsh_address))
4545

4646
# Same as the txid:vout the createrawtransaction RPC call requires
@@ -69,9 +69,8 @@
6969
# Create the unsigned transaction.
7070
tx = CMutableTransaction([txin], [txout])
7171

72-
# Calculate the signature hash for that transaction. Note how the script we use
73-
# is the witnessScript, not the redeemScript.
74-
sighash = SignatureHash(script=txin_witnessScript, txTo=tx, inIdx=0,
72+
# Calculate the signature hash for that transaction.
73+
sighash = SignatureHash(script=txin_redeemScript, txTo=tx, inIdx=0,
7574
hashtype=SIGHASH_ALL, amount=amount, sigversion=SIGVERSION_WITNESS_V0)
7675

7776
# Now sign it. We have to append the type of signature we want to the end, in
@@ -80,7 +79,7 @@
8079

8180

8281
# # Construct a witness for this P2WSH transaction and add to tx.
83-
witness = CScriptWitness([sig, txin_witnessScript])
82+
witness = CScriptWitness([sig, txin_redeemScript])
8483
tx.wit = CTxWitness([CTxInWitness(witness)])
8584

8685
# TODO: upgrade VerifyScript to support Segregated Witness and place verify the witness program here.

0 commit comments

Comments
 (0)