mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-22 14:52:41 +02:00
[test] parameterizable fee for make_chain and create_child_with_parents
This commit is contained in:
parent
313c09f7b7
commit
2b6b26e57c
@ -34,6 +34,7 @@ from test_framework.util import (
|
|||||||
satoshi_round,
|
satoshi_round,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DEFAULT_FEE = Decimal("0.0001")
|
||||||
|
|
||||||
class MiniWalletMode(Enum):
|
class MiniWalletMode(Enum):
|
||||||
"""Determines the transaction type the MiniWallet is creating and spending.
|
"""Determines the transaction type the MiniWallet is creating and spending.
|
||||||
@ -181,13 +182,13 @@ class MiniWallet:
|
|||||||
from_node.sendrawtransaction(tx_hex)
|
from_node.sendrawtransaction(tx_hex)
|
||||||
self.scan_tx(from_node.decoderawtransaction(tx_hex))
|
self.scan_tx(from_node.decoderawtransaction(tx_hex))
|
||||||
|
|
||||||
def make_chain(node, address, privkeys, parent_txid, parent_value, n=0, parent_locking_script=None):
|
def make_chain(node, address, privkeys, parent_txid, parent_value, n=0, parent_locking_script=None, fee=DEFAULT_FEE):
|
||||||
"""Build a transaction that spends parent_txid.vout[n] and produces one output with
|
"""Build a transaction that spends parent_txid.vout[n] and produces one output with
|
||||||
amount = parent_value with a fee deducted.
|
amount = parent_value with a fee deducted.
|
||||||
Return tuple (CTransaction object, raw hex, nValue, scriptPubKey of the output created).
|
Return tuple (CTransaction object, raw hex, nValue, scriptPubKey of the output created).
|
||||||
"""
|
"""
|
||||||
inputs = [{"txid": parent_txid, "vout": n}]
|
inputs = [{"txid": parent_txid, "vout": n}]
|
||||||
my_value = parent_value - Decimal("0.0001")
|
my_value = parent_value - fee
|
||||||
outputs = {address : my_value}
|
outputs = {address : my_value}
|
||||||
rawtx = node.createrawtransaction(inputs, outputs)
|
rawtx = node.createrawtransaction(inputs, outputs)
|
||||||
prevtxs = [{
|
prevtxs = [{
|
||||||
@ -201,12 +202,12 @@ def make_chain(node, address, privkeys, parent_txid, parent_value, n=0, parent_l
|
|||||||
tx = tx_from_hex(signedtx["hex"])
|
tx = tx_from_hex(signedtx["hex"])
|
||||||
return (tx, signedtx["hex"], my_value, tx.vout[0].scriptPubKey.hex())
|
return (tx, signedtx["hex"], my_value, tx.vout[0].scriptPubKey.hex())
|
||||||
|
|
||||||
def create_child_with_parents(node, address, privkeys, parents_tx, values, locking_scripts):
|
def create_child_with_parents(node, address, privkeys, parents_tx, values, locking_scripts, fee=DEFAULT_FEE):
|
||||||
"""Creates a transaction that spends the first output of each parent in parents_tx."""
|
"""Creates a transaction that spends the first output of each parent in parents_tx."""
|
||||||
num_parents = len(parents_tx)
|
num_parents = len(parents_tx)
|
||||||
total_value = sum(values)
|
total_value = sum(values)
|
||||||
inputs = [{"txid": tx.rehash(), "vout": 0} for tx in parents_tx]
|
inputs = [{"txid": tx.rehash(), "vout": 0} for tx in parents_tx]
|
||||||
outputs = {address : total_value - num_parents * Decimal("0.0001")}
|
outputs = {address : total_value - fee}
|
||||||
rawtx_child = node.createrawtransaction(inputs, outputs)
|
rawtx_child = node.createrawtransaction(inputs, outputs)
|
||||||
prevtxs = []
|
prevtxs = []
|
||||||
for i in range(num_parents):
|
for i in range(num_parents):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user