Browse Source

more accurate computation of transaction fees.

283
thomasv 12 years ago
parent
commit
a5168cc09f
  1. 2
      electrum
  2. 8
      gui/gui_classic.py
  3. 7
      gui/gui_gtk.py
  4. 12
      lib/bitcoin.py
  5. 12
      lib/wallet.py

2
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("-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("-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("-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("-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("-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") parser.add_option("-s", "--server", dest="server", default=None, help="set server host:port:protocol, where protocol is t or h")

8
gui/gui_classic.py

@ -795,6 +795,10 @@ class ElectrumWindow(QMainWindow):
self.show_message(str(e)) self.show_message(str(e))
return 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) self.run_hook('send_tx', tx)
if label: if label:
@ -1928,8 +1932,8 @@ class ElectrumWindow(QMainWindow):
fee_e = QLineEdit() fee_e = QLineEdit()
fee_e.setText("%s"% str( Decimal( self.wallet.fee)/100000000 ) ) fee_e.setText("%s"% str( Decimal( self.wallet.fee)/100000000 ) )
grid_wallet.addWidget(fee_e, 0, 2) grid_wallet.addWidget(fee_e, 0, 2)
msg = _('Fee per transaction input. Transactions involving multiple inputs tend to require a higher fee.') + ' ' \ msg = _('Fee per kilobyte of transaction.') + ' ' \
+ _('Recommended value') + ': 0.001' + _('Recommended value') + ': 0.0001'
grid_wallet.addWidget(HelpButton(msg), 0, 3) grid_wallet.addWidget(HelpButton(msg), 0, 3)
fee_e.textChanged.connect(lambda: numbify(fee_e,False)) fee_e.textChanged.connect(lambda: numbify(fee_e,False))
if not self.config.is_modifiable('fee'): if not self.config.is_modifiable('fee'):

7
gui/gui_gtk.py

@ -198,7 +198,7 @@ def run_settings_dialog(wallet, parent):
fee_entry.connect('changed', numbify, False) fee_entry.connect('changed', numbify, False)
fee_entry.show() fee_entry.show()
fee.pack_start(fee_entry,False,False, 10) 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() fee.show()
vbox.pack_start(fee, False,False, 5) vbox.pack_start(fee, False,False, 5)
@ -844,6 +844,11 @@ class ElectrumWindow:
self.show_message(str(e)) self.show_message(str(e))
return 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: if label:
self.wallet.labels[tx.hash()] = label self.wallet.labels[tx.hash()] = label

12
lib/bitcoin.py

@ -876,6 +876,18 @@ class Transaction:
return out 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(): def test_bip32():

12
lib/wallet.py

@ -74,7 +74,7 @@ class Wallet:
self.seed_version = config.get('seed_version', SEED_VERSION) self.seed_version = config.get('seed_version', SEED_VERSION)
self.gap_limit = config.get('gap_limit', 5) self.gap_limit = config.get('gap_limit', 5)
self.use_change = config.get('use_change',True) 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.num_zeros = int(config.get('num_zeros',0))
self.use_encryption = config.get('use_encryption', False) self.use_encryption = config.get('use_encryption', False)
self.seed = config.get('seed', '') # encrypted self.seed = config.get('seed', '') # encrypted
@ -565,14 +565,20 @@ class Wallet:
total += v total += v
inputs.append( item ) 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 if total >= amount + fee: break
else: else:
#print "not enough funds: %s %s"%(format_satoshis(total), format_satoshis(fee))
inputs = [] inputs = []
return inputs, total, fee return inputs, total, fee
def add_tx_change( self, outputs, amount, fee, total, change_addr=None ): def add_tx_change( self, outputs, amount, fee, total, change_addr=None ):
change_amount = total - ( amount + fee ) change_amount = total - ( amount + fee )
if change_amount != 0: if change_amount != 0:

Loading…
Cancel
Save