electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit fb53fc758d23ac0fe4f07b829cff36effb821afd
parent ad6a9084e5bc3a202ee6292c495160ecacdfcd1c
Author: ThomasV <thomasv1@gmx.de>
Date:   Wed,  5 Mar 2014 09:30:43 +0100

Merge pull request #604 from CodingAnarchy/master

change estimated_fee to include 34 bytes per output instead of hard-code...
Diffstat:
Mlib/wallet.py | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/wallet.py b/lib/wallet.py @@ -1087,7 +1087,7 @@ class NewWallet: return [x[1] for x in coins] - def choose_tx_inputs( self, amount, fixed_fee, domain = None ): + def choose_tx_inputs( self, amount, fixed_fee, num_outputs, domain = None ): """ todo: minimize tx size """ total = 0 fee = self.fee if fixed_fee is None else fixed_fee @@ -1107,7 +1107,7 @@ class NewWallet: v = item.get('value') total += v inputs.append(item) - fee = self.estimated_fee(inputs) if fixed_fee is None else fixed_fee + fee = self.estimated_fee(inputs, num_outputs) if fixed_fee is None else fixed_fee if total >= amount + fee: break else: inputs = [] @@ -1120,8 +1120,8 @@ class NewWallet: self.fee = fee self.storage.put('fee_per_kb', self.fee, True) - def estimated_fee(self, inputs): - estimated_size = len(inputs) * 180 + 80 # this assumes non-compressed keys + def estimated_fee(self, inputs, num_outputs): + estimated_size = len(inputs) * 180 + num_outputs * 34 # this assumes non-compressed keys fee = self.fee * int(math.ceil(estimated_size/1000.)) return fee @@ -1282,7 +1282,7 @@ class NewWallet: for address, x in outputs: assert is_valid(address), "Address " + address + " is invalid!" amount = sum( map(lambda x:x[1], outputs) ) - inputs, total, fee = self.choose_tx_inputs( amount, fee, domain ) + inputs, total, fee = self.choose_tx_inputs( amount, fee, len(outputs), domain ) if not inputs: raise ValueError("Not enough funds") self.add_input_info(inputs)