Move estimated_fee to Transaction class
It's not a function of the wallet but of the transaction so it more naturally belongs there.
This commit is contained in:
parent
e9061ea371
commit
90dee43998
|
@ -30,7 +30,7 @@ class CoinChooser(PrintError):
|
|||
def fee(self, tx, fixed_fee, fee_per_kb):
|
||||
if fixed_fee is not None:
|
||||
return fixed_fee
|
||||
return self.wallet.estimated_fee(tx, fee_per_kb)
|
||||
return tx.estimated_fee(fee_per_kb)
|
||||
|
||||
def dust_threshold(self):
|
||||
return 182 * 3 * MIN_RELAY_TX_FEE/1000
|
||||
|
@ -88,7 +88,7 @@ class CoinChooser(PrintError):
|
|||
elif change_amount > self.dust_threshold():
|
||||
tx.outputs.append(('address', change_addr, change_amount))
|
||||
# recompute fee including change output
|
||||
fee = self.wallet.estimated_fee(tx, fee_per_kb)
|
||||
fee = tx.estimated_fee(fee_per_kb)
|
||||
# remove change output
|
||||
tx.outputs.pop()
|
||||
# if change is still above dust threshold, re-add change output.
|
||||
|
|
|
@ -405,7 +405,7 @@ class Commands:
|
|||
output = ('address', address, amount)
|
||||
dummy_tx = Transaction.from_io(inputs, [output])
|
||||
fee_per_kb = self.wallet.fee_per_kb(self.config)
|
||||
fee = self.wallet.estimated_fee(dummy_tx, fee_per_kb)
|
||||
fee = dummy_tx.estimated_fee(fee_per_kb)
|
||||
amount -= fee
|
||||
else:
|
||||
amount = int(COIN*Decimal(amount))
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
import bitcoin
|
||||
from bitcoin import *
|
||||
from util import print_error
|
||||
from util import print_error, profiler
|
||||
import time
|
||||
import sys
|
||||
import struct
|
||||
|
@ -689,6 +689,14 @@ class Transaction:
|
|||
def get_fee(self):
|
||||
return self.input_value() - self.output_value()
|
||||
|
||||
@profiler
|
||||
def estimated_fee(self, fee_per_kb):
|
||||
estimated_size = len(self.serialize(-1)) / 2
|
||||
fee = int(fee_per_kb * estimated_size / 1000.)
|
||||
if fee < MIN_RELAY_TX_FEE:
|
||||
fee = MIN_RELAY_TX_FEE
|
||||
return fee
|
||||
|
||||
def signature_count(self):
|
||||
r = 0
|
||||
s = 0
|
||||
|
|
|
@ -645,7 +645,7 @@ class Abstract_Wallet(PrintError):
|
|||
dummy_tx = Transaction.from_io(inputs, [output])
|
||||
if fee is None:
|
||||
fee_per_kb = self.fee_per_kb(config)
|
||||
fee = self.estimated_fee(dummy_tx, fee_per_kb)
|
||||
fee = dummy_tx.estimated_fee(fee_per_kb)
|
||||
amount = max(0, sendable - fee)
|
||||
return amount, fee
|
||||
|
||||
|
@ -899,14 +899,6 @@ class Abstract_Wallet(PrintError):
|
|||
# this method can be overloaded
|
||||
return tx.get_fee()
|
||||
|
||||
@profiler
|
||||
def estimated_fee(self, tx, fee_per_kb):
|
||||
estimated_size = len(tx.serialize(-1))/2
|
||||
fee = int(fee_per_kb * estimated_size / 1000.)
|
||||
if fee < MIN_RELAY_TX_FEE: # and tx.requires_fee(self):
|
||||
fee = MIN_RELAY_TX_FEE
|
||||
return fee
|
||||
|
||||
def make_unsigned_transaction(self, coins, outputs, config, fixed_fee=None, change_addr=None):
|
||||
# check outputs
|
||||
for type, data, value in outputs:
|
||||
|
|
|
@ -207,7 +207,7 @@ class Wallet_2fa(Multisig_Wallet):
|
|||
return price
|
||||
|
||||
def estimated_fee(self, tx, fee_per_kb):
|
||||
fee = Multisig_Wallet.estimated_fee(self, tx, fee_per_kb)
|
||||
fee = tx.estimated_fee(fee_per_kb)
|
||||
fee += self.extra_fee(tx)
|
||||
return fee
|
||||
|
||||
|
@ -440,5 +440,3 @@ class TrustedCoinPlugin(BasePlugin):
|
|||
|
||||
wallet.add_master_public_key('x3/', xpub3)
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue