electrum

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

commit a5168cc09f9f3303c283eb6c72ff031098566e69
parent f3a1a57a7848bac11938ee68df4c8e9e63ffe4dc
Author: thomasv <thomasv@gitorious>
Date:   Sat, 23 Mar 2013 09:23:57 +0100

more accurate computation of transaction fees.

Diffstat:
Melectrum | 2+-
Mgui/gui_classic.py | 8++++++--
Mgui/gui_gtk.py | 7++++++-
Mlib/bitcoin.py | 12++++++++++++
Mlib/wallet.py | 12+++++++++---
5 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/electrum b/electrum @@ -72,7 +72,7 @@ def arg_parser(): parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses") parser.add_option("-b", "--balance", action="store_true", dest="show_balance", default=False, help="show the balance of listed addresses") parser.add_option("-l", "--labels", action="store_true", dest="show_labels", default=False, help="show the labels of listed addresses") - parser.add_option("-f", "--fee", dest="tx_fee", default="0.005", help="set tx fee") + parser.add_option("-f", "--fee", dest="tx_fee", default=None, help="set tx fee") parser.add_option("-F", "--fromaddr", dest="from_addr", default=None, help="set source address for payto/mktx. if it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet.") parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet") parser.add_option("-s", "--server", dest="server", default=None, help="set server host:port:protocol, where protocol is t or h") diff --git a/gui/gui_classic.py b/gui/gui_classic.py @@ -795,6 +795,10 @@ class ElectrumWindow(QMainWindow): self.show_message(str(e)) return + if tx.requires_fee(self.wallet.verifier) and fee == 0: + QMessageBox.warning(self, _('Error'), _("This transaction requires a fee, or it will not be propagated by the network."), _('OK')) + return + self.run_hook('send_tx', tx) if label: @@ -1928,8 +1932,8 @@ class ElectrumWindow(QMainWindow): fee_e = QLineEdit() fee_e.setText("%s"% str( Decimal( self.wallet.fee)/100000000 ) ) grid_wallet.addWidget(fee_e, 0, 2) - msg = _('Fee per transaction input. Transactions involving multiple inputs tend to require a higher fee.') + ' ' \ - + _('Recommended value') + ': 0.001' + msg = _('Fee per kilobyte of transaction.') + ' ' \ + + _('Recommended value') + ': 0.0001' grid_wallet.addWidget(HelpButton(msg), 0, 3) fee_e.textChanged.connect(lambda: numbify(fee_e,False)) if not self.config.is_modifiable('fee'): diff --git a/gui/gui_gtk.py b/gui/gui_gtk.py @@ -198,7 +198,7 @@ def run_settings_dialog(wallet, parent): fee_entry.connect('changed', numbify, False) fee_entry.show() fee.pack_start(fee_entry,False,False, 10) - add_help_button(fee, 'Fee per transaction input. Transactions involving multiple inputs tend to have a higher fee. Recommended value:0.0005') + add_help_button(fee, 'Fee per kilobyte of transaction. Recommended value:0.0001') fee.show() vbox.pack_start(fee, False,False, 5) @@ -843,6 +843,11 @@ class ElectrumWindow: except BaseException, e: self.show_message(str(e)) return + + if tx.requires_fee(self.wallet.verifier) and fee == 0: + self.show_message( "This transaction requires a fee, or it will not be propagated by the network." ) + return + if label: self.wallet.labels[tx.hash()] = label diff --git a/lib/bitcoin.py b/lib/bitcoin.py @@ -876,6 +876,18 @@ class Transaction: return out + def requires_fee(self, verifier): + threshold = 57600000 + size = len(self.raw)/2 + sum = 0 + for i in self.inputs: + age = verifier.get_confirmations(i["tx_hash"])[0] + sum += i["value"] * age + priority = sum / size + print_error(priority, threshold) + return priority < threshold + + def test_bip32(): diff --git a/lib/wallet.py b/lib/wallet.py @@ -74,7 +74,7 @@ class Wallet: self.seed_version = config.get('seed_version', SEED_VERSION) self.gap_limit = config.get('gap_limit', 5) self.use_change = config.get('use_change',True) - self.fee = int(config.get('fee',100000)) + self.fee = int(config.get('fee',10000)) self.num_zeros = int(config.get('num_zeros',0)) self.use_encryption = config.get('use_encryption', False) self.seed = config.get('seed', '') # encrypted @@ -565,14 +565,20 @@ class Wallet: total += v inputs.append( item ) - fee = self.fee*len(inputs) if fixed_fee is None else fixed_fee + if fixed_fee is None: + estimated_size = len(inputs) * 180 + 80 # this assumes non-compressed keys + fee = self.fee * round(estimated_size/1024.) + if fee == 0: fee = self.fee + else: + fee = fixed_fee if total >= amount + fee: break else: - #print "not enough funds: %s %s"%(format_satoshis(total), format_satoshis(fee)) inputs = [] return inputs, total, fee + + def add_tx_change( self, outputs, amount, fee, total, change_addr=None ): change_amount = total - ( amount + fee ) if change_amount != 0: