|
33 | 33 |
|
34 | 34 | # Create a witnessScript and corresponding redeemScript. Similar to a scriptPubKey |
35 | 35 | # 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]) |
39 | 39 |
|
40 | 40 |
|
41 | 41 | # Convert the P2WSH scriptPubKey to a base58 Bitcoin address and print it. |
42 | 42 | # 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) |
44 | 44 | print('Pay to:', str(txin_p2wsh_address)) |
45 | 45 |
|
46 | 46 | # Same as the txid:vout the createrawtransaction RPC call requires |
|
71 | 71 |
|
72 | 72 | # Calculate the signature hash for that transaction. Note how the script we use |
73 | 73 | # is the witnessScript, not the redeemScript. |
74 | | -sighash = SignatureHash(script=txin_witnessScript, txTo=tx, inIdx=0, |
| 74 | +sighash = SignatureHash(script=txin_redeemScript, txTo=tx, inIdx=0, |
75 | 75 | hashtype=SIGHASH_ALL, amount=amount, sigversion=SIGVERSION_WITNESS_V0) |
76 | 76 |
|
77 | 77 | # Now sign it. We have to append the type of signature we want to the end, in |
|
80 | 80 |
|
81 | 81 |
|
82 | 82 | # # Construct a witness for this P2WSH transaction and add to tx. |
83 | | -witness = CScriptWitness([sig, txin_witnessScript]) |
| 83 | +witness = CScriptWitness([sig, txin_redeemScript]) |
84 | 84 | tx.wit = CTxWitness([CTxInWitness(witness)]) |
85 | 85 |
|
86 | 86 | # TODO: upgrade VerifyScript to support Segregated Witness and place verify the witness program here. |
|
0 commit comments