Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show First 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | class TestNode(): | ||||
def relay_fee(self, cached=True): | def relay_fee(self, cached=True): | ||||
if not self.relay_fee_cache or not cached: | if not self.relay_fee_cache or not cached: | ||||
self.relay_fee_cache = self.getnetworkinfo()["relayfee"] | self.relay_fee_cache = self.getnetworkinfo()["relayfee"] | ||||
return self.relay_fee_cache | return self.relay_fee_cache | ||||
def calculate_fee(self, tx): | def calculate_fee(self, tx): | ||||
# Relay fee is in satoshis per KB. Thus the 1000, and the COIN added | """ Estimate the necessary fees (in sats) for an unsigned CTransaction assuming: | ||||
# to get back to an amount of satoshis. | - the current relayfee on node | ||||
- all inputs are compressed-key p2pkh, and will be signed ecdsa or schnorr | |||||
- all inputs currently unsigned (empty scriptSig) | |||||
""" | |||||
billable_size_estimate = tx.billable_size() | billable_size_estimate = tx.billable_size() | ||||
# Add some padding for signatures | # Add some padding for signatures / public keys | ||||
# NOTE: Fees must be calculated before signatures are added, | # 107 = length of PUSH(longest_sig = 72 bytes), PUSH(pubkey = 33 bytes) | ||||
# so they will never be included in the billable_size above. | billable_size_estimate += len(tx.vin) * 107 | ||||
billable_size_estimate += len(tx.vin) * 81 | |||||
# relay_fee gives a value in BCH per kB. | |||||
return int(self.relay_fee() / 1000 * billable_size_estimate * COIN) | return int(self.relay_fee() / 1000 * billable_size_estimate * COIN) | ||||
def calculate_fee_from_txid(self, txid): | def calculate_fee_from_txid(self, txid): | ||||
ctx = FromHex(CTransaction(), self.getrawtransaction(txid)) | ctx = FromHex(CTransaction(), self.getrawtransaction(txid)) | ||||
return self.calculate_fee(ctx) | return self.calculate_fee(ctx) | ||||
def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs): | def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs): | ||||
"""Add a p2p connection to the node. | """Add a p2p connection to the node. | ||||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |