URI: 
       tPrepare to calculate tx fee given a tx size - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit a4dd5acc48e75f1c6cb2873abacc5b6717ba3727
   DIR parent 39af17bc236602bced51d5feab6564ef26bd26e6
  HTML Author: Neil Booth <kyuupichan@gmail.com>
       Date:   Sun, 29 Nov 2015 12:41:54 +0900
       
       Prepare to calculate tx fee given a tx size
       
       Diffstat:
         M lib/coinchooser.py                  |       3 +--
         M lib/transaction.py                  |      16 ++++++++++++----
         M lib/wallet.py                       |      11 +++++++----
       
       3 files changed, 20 insertions(+), 10 deletions(-)
       ---
   DIR diff --git a/lib/coinchooser.py b/lib/coinchooser.py
       t@@ -32,8 +32,7 @@ class CoinChooser(PrintError):
                added to the transaction fee.'''
                amount = sum(map(lambda x: x[2], outputs))
                total = 0
       -        inputs = []
       -        tx = Transaction.from_io(inputs, outputs)
       +        tx = Transaction.from_io([], outputs)
                fee = fee_estimator(tx)
                # add inputs, sorted by age
                for item in coins:
   DIR diff --git a/lib/transaction.py b/lib/transaction.py
       t@@ -689,14 +689,22 @@ 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.)
       +    @classmethod
       +    def estimated_fee_for_size(self, 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 < MIN_RELAY_TX_FEE:
                    fee = MIN_RELAY_TX_FEE
                return fee
        
       +    @profiler
       +    def estimated_fee(self, fee_per_kb):
       +        '''Return an estimated fee given a fee per kB in satoshis.'''
       +        # Remember self.serialize returns an ASCII hex string
       +        size = len(self.serialize(-1)) / 2
       +        return self.estimated_fee_for_size(fee_per_kb, size)
       +
            def signature_count(self):
                r = 0
                s = 0
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -927,11 +927,14 @@ class Abstract_Wallet(PrintError):
                    else:
                        change_addrs = [address]
        
       -        fee_per_kb = self.fee_per_kb(config)
       -        def fee_estimator(tx):
       -            if fixed_fee is not None:
       +        # Fee estimator
       +        if fixed_fee is None:
       +            fee_per_kb = self.fee_per_kb(config)
       +            def fee_estimator(tx):
       +                return tx.estimated_fee(fee_per_kb)
       +        else:
       +            def fee_estimator(tx):
                        return fixed_fee
       -            return tx.estimated_fee(fee_per_kb)
        
                # Change <= dust threshold is added to the tx fee
                dust_threshold = 182 * 3 * MIN_RELAY_TX_FEE / 1000