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:
@@ -30,7 +30,7 @@ class CoinChooser(PrintError):
|
|||||||
def fee(self, tx, fixed_fee, fee_per_kb):
|
def fee(self, tx, fixed_fee, fee_per_kb):
|
||||||
if fixed_fee is not None:
|
if fixed_fee is not None:
|
||||||
return fixed_fee
|
return fixed_fee
|
||||||
return self.wallet.estimated_fee(tx, fee_per_kb)
|
return tx.estimated_fee(fee_per_kb)
|
||||||
|
|
||||||
def dust_threshold(self):
|
def dust_threshold(self):
|
||||||
return 182 * 3 * MIN_RELAY_TX_FEE/1000
|
return 182 * 3 * MIN_RELAY_TX_FEE/1000
|
||||||
@@ -88,7 +88,7 @@ class CoinChooser(PrintError):
|
|||||||
elif change_amount > self.dust_threshold():
|
elif change_amount > self.dust_threshold():
|
||||||
tx.outputs.append(('address', change_addr, change_amount))
|
tx.outputs.append(('address', change_addr, change_amount))
|
||||||
# recompute fee including change output
|
# recompute fee including change output
|
||||||
fee = self.wallet.estimated_fee(tx, fee_per_kb)
|
fee = tx.estimated_fee(fee_per_kb)
|
||||||
# remove change output
|
# remove change output
|
||||||
tx.outputs.pop()
|
tx.outputs.pop()
|
||||||
# if change is still above dust threshold, re-add change output.
|
# if change is still above dust threshold, re-add change output.
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ class Commands:
|
|||||||
output = ('address', address, amount)
|
output = ('address', address, amount)
|
||||||
dummy_tx = Transaction.from_io(inputs, [output])
|
dummy_tx = Transaction.from_io(inputs, [output])
|
||||||
fee_per_kb = self.wallet.fee_per_kb(self.config)
|
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
|
amount -= fee
|
||||||
else:
|
else:
|
||||||
amount = int(COIN*Decimal(amount))
|
amount = int(COIN*Decimal(amount))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
import bitcoin
|
import bitcoin
|
||||||
from bitcoin import *
|
from bitcoin import *
|
||||||
from util import print_error
|
from util import print_error, profiler
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
@@ -689,6 +689,14 @@ class Transaction:
|
|||||||
def get_fee(self):
|
def get_fee(self):
|
||||||
return self.input_value() - self.output_value()
|
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):
|
def signature_count(self):
|
||||||
r = 0
|
r = 0
|
||||||
s = 0
|
s = 0
|
||||||
|
|||||||
@@ -645,7 +645,7 @@ class Abstract_Wallet(PrintError):
|
|||||||
dummy_tx = Transaction.from_io(inputs, [output])
|
dummy_tx = Transaction.from_io(inputs, [output])
|
||||||
if fee is None:
|
if fee is None:
|
||||||
fee_per_kb = self.fee_per_kb(config)
|
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)
|
amount = max(0, sendable - fee)
|
||||||
return amount, fee
|
return amount, fee
|
||||||
|
|
||||||
@@ -899,14 +899,6 @@ class Abstract_Wallet(PrintError):
|
|||||||
# this method can be overloaded
|
# this method can be overloaded
|
||||||
return tx.get_fee()
|
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):
|
def make_unsigned_transaction(self, coins, outputs, config, fixed_fee=None, change_addr=None):
|
||||||
# check outputs
|
# check outputs
|
||||||
for type, data, value in outputs:
|
for type, data, value in outputs:
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ class Wallet_2fa(Multisig_Wallet):
|
|||||||
return price
|
return price
|
||||||
|
|
||||||
def estimated_fee(self, tx, fee_per_kb):
|
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)
|
fee += self.extra_fee(tx)
|
||||||
return fee
|
return fee
|
||||||
|
|
||||||
@@ -440,5 +440,3 @@ class TrustedCoinPlugin(BasePlugin):
|
|||||||
|
|
||||||
wallet.add_master_public_key('x3/', xpub3)
|
wallet.add_master_public_key('x3/', xpub3)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user