commit 90dee439985c119028f38e7f8c1aa7ced6f244af
parent e9061ea371478c75d7883a81b94acda0231b486b
Author: Neil Booth <kyuupichan@gmail.com>
Date: Sat, 28 Nov 2015 21:28:54 +0900
Move estimated_fee to Transaction class
It's not a function of the wallet but of the transaction
so it more naturally belongs there.
Diffstat:
5 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/lib/coinchooser.py b/lib/coinchooser.py
@@ -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.
diff --git a/lib/commands.py b/lib/commands.py
@@ -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))
diff --git a/lib/transaction.py b/lib/transaction.py
@@ -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
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -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:
diff --git a/plugins/trustedcoin/trustedcoin.py b/plugins/trustedcoin/trustedcoin.py
@@ -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
-
-