tmore accurate computation of transaction fees. - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit a5168cc09f9f3303c283eb6c72ff031098566e69 DIR parent f3a1a57a7848bac11938ee68df4c8e9e63ffe4dc HTML Author: thomasv <thomasv@gitorious> Date: Sat, 23 Mar 2013 09:23:57 +0100 more accurate computation of transaction fees. Diffstat: M electrum | 2 +- M gui/gui_classic.py | 8 ++++++-- M gui/gui_gtk.py | 7 ++++++- M lib/bitcoin.py | 12 ++++++++++++ M lib/wallet.py | 12 +++++++++--- 5 files changed, 34 insertions(+), 7 deletions(-) --- DIR diff --git a/electrum b/electrum t@@ -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") DIR diff --git a/gui/gui_classic.py b/gui/gui_classic.py t@@ -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: t@@ -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'): DIR diff --git a/gui/gui_gtk.py b/gui/gui_gtk.py t@@ -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) t@@ -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 DIR diff --git a/lib/bitcoin.py b/lib/bitcoin.py t@@ -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(): DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -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 t@@ -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: