move estimate_fee back to wallet
This commit is contained in:
parent
0b54ed0243
commit
eb36884c66
|
@ -404,8 +404,7 @@ class Commands:
|
|||
self.wallet.add_input_info(i)
|
||||
output = (TYPE_ADDRESS, address, amount)
|
||||
dummy_tx = Transaction.from_io(inputs, [output])
|
||||
fee_per_kb = self.wallet.fee_per_kb(self.config)
|
||||
fee = dummy_tx.estimated_fee(fee_per_kb)
|
||||
fee = self.wallet.estimate_fee(self.config, dummy_tx.estimated_size())
|
||||
amount -= fee
|
||||
else:
|
||||
amount = int(COIN*Decimal(amount))
|
||||
|
|
|
@ -715,15 +715,6 @@ class Transaction:
|
|||
def is_final(self):
|
||||
return not any([x.get('sequence') < 0xffffffff - 1 for x in self.inputs()])
|
||||
|
||||
@classmethod
|
||||
def fee_for_size(self, relay_fee, fee_per_kb, size):
|
||||
'''Given a fee per kB in satoshis, and a tx size in bytes,
|
||||
returns the transaction fee.'''
|
||||
fee = int(fee_per_kb * size / 1000.)
|
||||
if fee < relay_fee:
|
||||
fee = relay_fee
|
||||
return fee
|
||||
|
||||
@profiler
|
||||
def estimated_size(self):
|
||||
'''Return an estimated tx size in bytes.'''
|
||||
|
@ -734,10 +725,6 @@ class Transaction:
|
|||
'''Return an estimated of serialized input size in bytes.'''
|
||||
return len(self.serialize_input(txin, -1, -1)) / 2
|
||||
|
||||
def estimated_fee(self, relay_fee, fee_per_kb):
|
||||
'''Return an estimated fee given a fee per kB in satoshis.'''
|
||||
return self.fee_for_size(relay_fee, fee_per_kb, self.estimated_size())
|
||||
|
||||
def signature_count(self):
|
||||
r = 0
|
||||
s = 0
|
||||
|
|
|
@ -662,8 +662,7 @@ class Abstract_Wallet(PrintError):
|
|||
output = (TYPE_ADDRESS, addr, sendable)
|
||||
dummy_tx = Transaction.from_io(inputs, [output])
|
||||
if fee is None:
|
||||
fee_per_kb = self.fee_per_kb(config)
|
||||
fee = dummy_tx.estimated_fee(self.relayfee(), fee_per_kb)
|
||||
fee = self.estimate_fee(config, dummy_tx.estimated_size())
|
||||
amount = max(0, sendable - fee)
|
||||
return amount, fee
|
||||
|
||||
|
@ -957,9 +956,7 @@ class Abstract_Wallet(PrintError):
|
|||
|
||||
# Fee estimator
|
||||
if fixed_fee is None:
|
||||
fee_estimator = partial(Transaction.fee_for_size,
|
||||
self.relayfee(),
|
||||
self.fee_per_kb(config))
|
||||
fee_estimator = partial(self.estimate_fee, config)
|
||||
else:
|
||||
fee_estimator = lambda size: fixed_fee
|
||||
|
||||
|
@ -978,6 +975,11 @@ class Abstract_Wallet(PrintError):
|
|||
run_hook('make_unsigned_transaction', self, tx)
|
||||
return tx
|
||||
|
||||
def estimate_fee(self, config, size):
|
||||
fee = int(self.fee_per_kb(config) * size / 1000.)
|
||||
fee = max(fee, self.relayfee())
|
||||
return fee
|
||||
|
||||
def mktx(self, outputs, password, config, fee=None, change_addr=None, domain=None):
|
||||
coins = self.get_spendable_coins(domain)
|
||||
tx = self.make_unsigned_transaction(coins, outputs, config, fee, change_addr)
|
||||
|
|
|
@ -221,11 +221,6 @@ class Wallet_2fa(Multisig_Wallet):
|
|||
return 0
|
||||
return price
|
||||
|
||||
def estimated_fee(self, tx, fee_per_kb):
|
||||
fee = tx.estimated_fee(fee_per_kb)
|
||||
fee += self.extra_fee(tx)
|
||||
return fee
|
||||
|
||||
def make_unsigned_transaction(self, coins, outputs, config,
|
||||
fixed_fee=None, change_addr=None):
|
||||
tx = BIP32_Wallet.make_unsigned_transaction(
|
||||
|
|
Loading…
Reference in New Issue