MiniWallet.{create,send}_self_transfer_multi
are introduced which serve as a replacement for chain_transaction
. With this, it should be also quite straight-forward to change the larger related test mempool_packages.py
to use MiniWallet.
MiniWallet.{create,send}_self_transfer_multi
are introduced which serve as a replacement for chain_transaction
. With this, it should be also quite straight-forward to change the larger related test mempool_packages.py
to use MiniWallet.
187@@ -188,6 +188,38 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
188 txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
189 return txid, 1
190
191+ def chain_tx(self, node, parent_txids, num_outputs=1, fee_per_output=1000):
192+ """
193+ Build and send a transaction that spends the given inputs and creates a
0 Build and send a transaction that spends one output of the given txids and creates a
I think it only spends the first found (random) output
194+ certain number of outputs with equal amounts.
195+
196+ Returns a list of newly created UTXOs, ordered by vout index.
197+ """
198+ # create simple tx template (1 input, 1 output)
199+ assert_greater_than_or_equal(len(utxos), 1)
210+
211+ # adapt output amounts (use fixed fee per output)
212+ inputs_value_total = sum([int(COIN * utxo['value']) for utxo in utxos])
213+ outputs_value_total = inputs_value_total - fee_per_output * num_outputs
214+ for i in range(num_outputs):
215+ tx.vout[i].nValue = outputs_value_total // num_outputs
create_self_transfer_multi
helper for symmetry with the existing helpers?
187@@ -188,6 +188,35 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
188 txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
189 return txid, 1
190
191+ def chain_tx(self, node, utxos, num_outputs=1, fee_per_output=1000):
nit: (Some renames for symmetry)
0 def send_self_transfer_multi(self, node_from, utxos, *, num_outputs=1, fee_per_output=1000):
Thanks again for the valuable feedback @MarcoFalke! Force-pushed with the following suggested changes:
create_self_transfer_multi
/send_self_transfer_multi
for the symmetry with existing helpers (https://github.com/bitcoin/bitcoin/pull/24637#discussion_r832218529 and #24637 (review))The PR description was also adapted accordingly.
197+ """
198+ tx = self.create_self_transfer_multi(from_node, utxos, **kwargs)
199+ txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
200+ return [self.get_utxo(txid=txid, vout=vout) for vout in range(len(tx.vout))]
201+
202+ def create_self_transfer_multi(self, from_node, utxos, *, num_outputs=1, fee_per_output=1000):
nit
0 def create_self_transfer_multi(self, *, from_node, utxos, num_outputs=1, fee_per_output=1000):
187@@ -188,6 +188,41 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
188 txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
189 return txid, 1
190
191+ def send_self_transfer_multi(self, from_node, utxos, **kwargs):
nit:
0 def send_self_transfer_multi(self, *, from_node, utxos, **kwargs):
Also, “utxos” can be renamed to “inputs” or “utxos_to_spend”.
0 def send_self_transfer_multi(self, **kwargs):
or maybe even just
195+
196+ Returns a list of newly created UTXOs, ordered by vout index.
197+ """
198+ tx = self.create_self_transfer_multi(from_node, utxos, **kwargs)
199+ txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
200+ return [self.get_utxo(txid=txid, vout=vout) for vout in range(len(tx.vout))]
nit: Maybe return a dict similar to send_self_transfer
?
0 return {"new_utxo":[self.get_utxo(txid=txid, vout=vout) for vout in range(len(tx.vout))], "tx": tx}
This test can now be run even with the Bitcoin Core wallet disabled.
Force-pushed again with the following changes:
{create,send}_self_transfer_multi
methods must be passed as keyword arguments now (to be consistent with {create,self}_transfer
methods)send_self_transfer_multi
returns a dictionary with several informations (txid, tx serialized as hex, tx as CTransaction instance, list of new UTXOs)chain_tx
in the test in order to avoid repeatedly passing from_node
arguments and being able to pass utxos getrawtransaction
RPC at the end of the test is not needed anymore, since we can directly access the tx
field from the result dictionary223+
224+ # adapt output amounts (use fixed fee per output)
225+ inputs_value_total = sum([int(COIN * utxo['value']) for utxo in utxos_to_spend])
226+ outputs_value_total = inputs_value_total - fee_per_output * num_outputs
227+ for i in range(num_outputs):
228+ tx.vout[i].nValue = outputs_value_total // num_outputs
nit: Haven’t tried, but this might be possible to write shorter
0 for o in tx.vout:
1 o.nValue = outputs_value_total // num_outputs
ACK 2b6dd4e75b3ad2daff553fde018fe4c8f1187878 💾
Signature:
0-----BEGIN PGP SIGNED MESSAGE-----
1Hash: SHA512
2
3ACK 2b6dd4e75b3ad2daff553fde018fe4c8f1187878 💾
4-----BEGIN PGP SIGNATURE-----
5
6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
7pUh0jgwAlqAJ870kGVFw8j59DsDnOgazr4Q3gZs3ev7+QPUDwABrwzfJggjUWYy8
8G+fBs+4b/buewrlpMpLHMoAza3n1ib4yiR4Ayebbj65vyVhRVERBncLMlbnYDU7c
9VQR0Fkuz5FTza9P7BuIegO3JPOXxPnJi5AKg8xSsIY7vZfNvXuwn74zyZqI14hCm
10iDG4JtKtyiYpL+Mct9UWD9mKBUlEW1KnESejKVj5eQTG5ww0TijlNCfQ7W+JTE3m
11ndwqmbuPI5RM7YqytsKuTpPc584nqr/zM1/AuIGM7aEM8BdwTW5StJCL6AuPL1B+
12wD3w7HVltleskkvmj2407xPZkiGanxzOE7L3Q5G0GiWDCJFYU6jqXbRoJ8ml/oPn
13b8kILOTtLvEqRNry8bOGiOAxTGZG8VkdsvRtjxBE/HLGtgX/avlN9ELPPvLE6GKD
14rY+isoIqlqqGGZfLegweVnCuLJVS0+1o8HJAgwPyhyejVXbcU1EACstphCNdMtd8
15s9QdQ3hV
16=mjSo
17-----END PGP SIGNATURE-----