@@ -146,20 +146,28 @@ def scan_txs(self, txs):
146
146
self .scan_tx (tx )
147
147
148
148
def sign_tx (self , tx , fixed_length = True ):
149
- """Sign tx that has been created by MiniWallet in P2PK mode"""
150
- assert_equal (self ._mode , MiniWalletMode .RAW_P2PK )
151
- (sighash , err ) = LegacySignatureHash (CScript (self ._scriptPubKey ), tx , 0 , SIGHASH_ALL )
152
- assert err is None
153
- # for exact fee calculation, create only signatures with fixed size by default (>49.89% probability):
154
- # 65 bytes: high-R val (33 bytes) + low-S val (32 bytes)
155
- # with the DER header/skeleton data of 6 bytes added, this leads to a target size of 71 bytes
156
- der_sig = b''
157
- while not len (der_sig ) == 71 :
158
- der_sig = self ._priv_key .sign_ecdsa (sighash )
159
- if not fixed_length :
160
- break
161
- tx .vin [0 ].scriptSig = CScript ([der_sig + bytes (bytearray ([SIGHASH_ALL ]))])
162
- tx .rehash ()
149
+ if self ._mode == MiniWalletMode .RAW_P2PK :
150
+ (sighash , err ) = LegacySignatureHash (CScript (self ._scriptPubKey ), tx , 0 , SIGHASH_ALL )
151
+ assert err is None
152
+ # for exact fee calculation, create only signatures with fixed size by default (>49.89% probability):
153
+ # 65 bytes: high-R val (33 bytes) + low-S val (32 bytes)
154
+ # with the DER header/skeleton data of 6 bytes added, this leads to a target size of 71 bytes
155
+ der_sig = b''
156
+ while not len (der_sig ) == 71 :
157
+ der_sig = self ._priv_key .sign_ecdsa (sighash )
158
+ if not fixed_length :
159
+ break
160
+ tx .vin [0 ].scriptSig = CScript ([der_sig + bytes (bytearray ([SIGHASH_ALL ]))])
161
+ tx .rehash ()
162
+ elif self ._mode == MiniWalletMode .RAW_OP_TRUE :
163
+ for i in range (len (tx .vin )):
164
+ tx .vin [i ].scriptSig = CScript ([OP_NOP ] * 43 ) # pad to identical size
165
+ elif self ._mode == MiniWalletMode .ADDRESS_OP_TRUE :
166
+ tx .wit .vtxinwit = [CTxInWitness ()] * len (tx .vin )
167
+ for i in range (len (tx .vin )):
168
+ tx .wit .vtxinwit [i ].scriptWitness .stack = [CScript ([OP_TRUE ]), bytes ([LEAF_VERSION_TAPSCRIPT ]) + self ._internal_key ]
169
+ else :
170
+ assert False
163
171
164
172
def generate (self , num_blocks , ** kwargs ):
165
173
"""Generate blocks with coinbase outputs to the internal address, and call rescan_utxos"""
@@ -273,17 +281,7 @@ def create_self_transfer_multi(
273
281
tx .vout = [CTxOut (amount_per_output , bytearray (self ._scriptPubKey )) for _ in range (num_outputs )]
274
282
tx .nLockTime = locktime
275
283
276
- if self ._mode == MiniWalletMode .RAW_P2PK :
277
- self .sign_tx (tx )
278
- elif self ._mode == MiniWalletMode .RAW_OP_TRUE :
279
- for i in range (len (utxos_to_spend )):
280
- tx .vin [i ].scriptSig = CScript ([OP_NOP ] * 43 ) # pad to identical size
281
- elif self ._mode == MiniWalletMode .ADDRESS_OP_TRUE :
282
- tx .wit .vtxinwit = [CTxInWitness ()] * len (utxos_to_spend )
283
- for i in range (len (utxos_to_spend )):
284
- tx .wit .vtxinwit [i ].scriptWitness .stack = [CScript ([OP_TRUE ]), bytes ([LEAF_VERSION_TAPSCRIPT ]) + self ._internal_key ]
285
- else :
286
- assert False
284
+ self .sign_tx (tx )
287
285
288
286
if target_weight :
289
287
self ._bulk_tx (tx , target_weight )
0 commit comments