mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-26 08:51:55 +02:00
test: Allow absolute fee in MiniWallet create_self_transfer
This commit is contained in:
parent
c892cb7d8d
commit
2222842ae7
@ -197,7 +197,7 @@ class MiniWallet:
|
|||||||
return utxos
|
return utxos
|
||||||
|
|
||||||
def send_self_transfer(self, *, from_node, **kwargs):
|
def send_self_transfer(self, *, from_node, **kwargs):
|
||||||
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
"""Call create_self_transfer and send the transaction."""
|
||||||
tx = self.create_self_transfer(**kwargs)
|
tx = self.create_self_transfer(**kwargs)
|
||||||
self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
|
self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
|
||||||
return tx
|
return tx
|
||||||
@ -272,16 +272,18 @@ class MiniWallet:
|
|||||||
"tx": tx,
|
"tx": tx,
|
||||||
}
|
}
|
||||||
|
|
||||||
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None, locktime=0, sequence=0):
|
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), fee=Decimal("0"), utxo_to_spend=None, locktime=0, sequence=0):
|
||||||
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
"""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."""
|
||||||
utxo_to_spend = utxo_to_spend or self.get_utxo()
|
utxo_to_spend = utxo_to_spend or self.get_utxo()
|
||||||
|
assert fee_rate >= 0
|
||||||
|
assert fee >= 0
|
||||||
if self._mode in (MiniWalletMode.RAW_OP_TRUE, MiniWalletMode.ADDRESS_OP_TRUE):
|
if self._mode in (MiniWalletMode.RAW_OP_TRUE, MiniWalletMode.ADDRESS_OP_TRUE):
|
||||||
vsize = Decimal(104) # anyone-can-spend
|
vsize = Decimal(104) # anyone-can-spend
|
||||||
elif self._mode == MiniWalletMode.RAW_P2PK:
|
elif self._mode == MiniWalletMode.RAW_P2PK:
|
||||||
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
|
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
send_value = utxo_to_spend["value"] - (fee_rate * vsize / 1000)
|
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
|
||||||
assert send_value > 0
|
assert send_value > 0
|
||||||
|
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user