Skip to content

Commit e167162

Browse files
committed
merge bitcoin#25522: Remove -acceptnonstdtxn=1 from feature_rbf.py
excludes: - fad690b (we don't support RBF)
1 parent a5cb9b4 commit e167162

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/functional/test_framework/wallet.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def get_utxo(self, *, txid: str = '', vout: Optional[int] = None, mark_as_spent=
179179
return self._utxos[index]
180180

181181
def send_self_transfer(self, *, from_node, **kwargs):
182-
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
182+
"""Call create_self_transfer and send the transaction."""
183183
tx = self.create_self_transfer(**kwargs)
184184
self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
185185
return tx
@@ -214,21 +214,27 @@ def create_self_transfer_multi(
214214
*,
215215
utxos_to_spend: Optional[List[dict]] = None,
216216
num_outputs=1,
217+
amount_per_output=0,
217218
sequence=0,
218219
fee_per_output=1000,
219220
):
220221
"""
221222
Create and return a transaction that spends the given UTXOs and creates a
222-
certain number of outputs with equal amounts.
223+
certain number of outputs with equal amounts. The output amounts can be
224+
set by amount_per_output or automatically calculated with a fee_per_output.
223225
"""
224226
utxos_to_spend = utxos_to_spend or [self.get_utxo()]
227+
sequence = [sequence] * len(utxos_to_spend) if type(sequence) is int else sequence
228+
assert_equal(len(utxos_to_spend), len(sequence))
225229
# create simple tx template (1 input, 1 output)
226230
tx = self.create_self_transfer(
227231
fee_rate=0,
228-
utxo_to_spend=utxos_to_spend[0], sequence=sequence)["tx"]
232+
utxo_to_spend=utxos_to_spend[0])["tx"]
229233

230234
# duplicate inputs, witnesses and outputs
231235
tx.vin = [deepcopy(tx.vin[0]) for _ in range(len(utxos_to_spend))]
236+
for txin, seq in zip(tx.vin, sequence):
237+
txin.nSequence = seq
232238
tx.vout = [deepcopy(tx.vout[0]) for _ in range(num_outputs)]
233239

234240
# adapt input prevouts
@@ -239,7 +245,7 @@ def create_self_transfer_multi(
239245
inputs_value_total = sum([int(COIN * utxo['value']) for utxo in utxos_to_spend])
240246
outputs_value_total = inputs_value_total - fee_per_output * num_outputs
241247
for o in tx.vout:
242-
o.nValue = outputs_value_total // num_outputs
248+
o.nValue = amount_per_output or (outputs_value_total // num_outputs)
243249
txid = tx.rehash()
244250
return {
245251
"new_utxos": [self._create_utxo(
@@ -253,21 +259,23 @@ def create_self_transfer_multi(
253259
"tx": tx,
254260
}
255261

256-
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None, locktime=0, sequence=0):
257-
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
262+
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), fee=Decimal("0"), utxo_to_spend=None, locktime=0, sequence=0):
263+
"""Create and return a tx with the specified fee. If fee is 0, use fee_rate, where the resulting fee may be exact or at most one satoshi higher than needed."""
258264
utxo_to_spend = utxo_to_spend or self.get_utxo()
265+
assert fee_rate >= 0
266+
assert fee >= 0
259267
if self._mode in (MiniWalletMode.RAW_OP_TRUE, MiniWalletMode.ADDRESS_OP_TRUE):
260268
vsize = Decimal(85) # anyone-can-spend
261269
elif self._mode == MiniWalletMode.RAW_P2PK:
262270
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
263271
else:
264272
assert False
265-
send_value = utxo_to_spend["value"] - (fee_rate * vsize / 1000)
273+
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
266274
assert send_value > 0
267275

268276
tx = CTransaction()
269277
tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']), nSequence=sequence)]
270-
tx.vout = [CTxOut(int(COIN * send_value), self._scriptPubKey)]
278+
tx.vout = [CTxOut(int(COIN * send_value), bytearray(self._scriptPubKey))]
271279
tx.nLockTime = locktime
272280
if self._mode == MiniWalletMode.RAW_P2PK:
273281
self.sign_tx(tx)

0 commit comments

Comments
 (0)