17
17
from test_framework .script import (
18
18
CScript ,
19
19
OP_1 ,
20
- OP_2 ,
21
20
OP_DROP ,
22
21
OP_TRUE ,
23
22
)
36
35
# Construct 2 trivial P2SH's and the ScriptSigs that spend them
37
36
# So we can create many transactions without needing to spend
38
37
# time signing.
39
- REDEEM_SCRIPT_1 = CScript ([OP_1 , OP_DROP ])
40
- REDEEM_SCRIPT_2 = CScript ([OP_2 , OP_DROP ])
41
- P2SH_1 = script_to_p2sh_script (REDEEM_SCRIPT_1 )
42
- P2SH_2 = script_to_p2sh_script (REDEEM_SCRIPT_2 )
43
-
44
- # Associated ScriptSig's to spend satisfy P2SH_1 and P2SH_2
45
- SCRIPT_SIG = [CScript ([OP_TRUE , REDEEM_SCRIPT_1 ]), CScript ([OP_TRUE , REDEEM_SCRIPT_2 ])]
38
+ SCRIPT = CScript ([OP_1 , OP_DROP ])
39
+ P2SH = script_to_p2sh_script (SCRIPT )
40
+ REDEEM_SCRIPT = CScript ([OP_TRUE , SCRIPT ])
46
41
47
42
48
43
def small_txpuzzle_randfee (from_node , conflist , unconflist , amount , min_fee , fee_increment ):
@@ -73,12 +68,12 @@ def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee
73
68
tx .vin .append (CTxIn (COutPoint (int (t ["txid" ], 16 ), t ["vout" ]), b"" ))
74
69
if total_in <= amount + fee :
75
70
raise RuntimeError (f"Insufficient funds: need { amount + fee } , have { total_in } " )
76
- tx .vout .append (CTxOut (int ((total_in - amount - fee ) * COIN ), P2SH_1 ))
77
- tx .vout .append (CTxOut (int (amount * COIN ), P2SH_2 ))
71
+ tx .vout .append (CTxOut (int ((total_in - amount - fee ) * COIN ), P2SH ))
72
+ tx .vout .append (CTxOut (int (amount * COIN ), P2SH ))
78
73
# These transactions don't need to be signed, but we still have to insert
79
74
# the ScriptSig that will satisfy the ScriptPubKey.
80
75
for inp in tx .vin :
81
- inp .scriptSig = SCRIPT_SIG [ inp . prevout . n ]
76
+ inp .scriptSig = REDEEM_SCRIPT
82
77
txid = from_node .sendrawtransaction (hexstring = tx .serialize ().hex (), maxfeerate = 0 )
83
78
unconflist .append ({"txid" : txid , "vout" : 0 , "amount" : total_in - amount - fee })
84
79
unconflist .append ({"txid" : txid , "vout" : 1 , "amount" : amount })
@@ -100,15 +95,15 @@ def split_inputs(from_node, txins, txouts, initial_split=False):
100
95
101
96
half_change = satoshi_round (prevtxout ["amount" ] / 2 )
102
97
rem_change = prevtxout ["amount" ] - half_change - Decimal ("0.00001000" )
103
- tx .vout .append (CTxOut (int (half_change * COIN ), P2SH_1 ))
104
- tx .vout .append (CTxOut (int (rem_change * COIN ), P2SH_2 ))
98
+ tx .vout .append (CTxOut (int (half_change * COIN ), P2SH ))
99
+ tx .vout .append (CTxOut (int (rem_change * COIN ), P2SH ))
105
100
106
101
# If this is the initial split we actually need to sign the transaction
107
102
# Otherwise we just need to insert the proper ScriptSig
108
103
if (initial_split ):
109
104
completetx = from_node .signrawtransactionwithwallet (tx .serialize ().hex ())["hex" ]
110
105
else :
111
- tx .vin [0 ].scriptSig = SCRIPT_SIG [ prevtxout [ "vout" ]]
106
+ tx .vin [0 ].scriptSig = REDEEM_SCRIPT
112
107
completetx = tx .serialize ().hex ()
113
108
txid = from_node .sendrawtransaction (hexstring = completetx , maxfeerate = 0 )
114
109
txouts .append ({"txid" : txid , "vout" : 0 , "amount" : half_change })
@@ -163,8 +158,8 @@ def send_tx(node, utxo, feerate):
163
158
fee = tx_size * feerate
164
159
165
160
tx = CTransaction ()
166
- tx .vin = [CTxIn (COutPoint (int (utxo ["txid" ], 16 ), utxo ["vout" ]), SCRIPT_SIG [ utxo [ "vout" ]] )]
167
- tx .vout = [CTxOut (int (utxo ["amount" ] * COIN ) - fee , P2SH_1 )]
161
+ tx .vin = [CTxIn (COutPoint (int (utxo ["txid" ], 16 ), utxo ["vout" ]), REDEEM_SCRIPT )]
162
+ tx .vout = [CTxOut (int (utxo ["amount" ] * COIN ) - fee , P2SH )]
168
163
txid = node .sendrawtransaction (tx .serialize ().hex ())
169
164
170
165
return txid
0 commit comments