This commit is contained in:
ThomasV 2016-02-03 10:29:31 +01:00
parent 3ee61c4c6e
commit 2a507b91c1
2 changed files with 10 additions and 6 deletions

View File

@ -1011,7 +1011,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def on_shortcut():
inputs = self.get_coins()
fee = self.fee_e.get_amount() if self.fee_e.isModified() else None
amount, fee = self.wallet.get_max_amount(self.config, inputs, fee)
addr = self.get_payto_or_dummy()
amount, fee = self.wallet.get_max_amount(self.config, inputs, addr, fee)
if not self.fee_e.isModified():
self.fee_e.setAmount(fee)
self.amount_e.setAmount(max(0, amount))
@ -1078,13 +1079,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def update_fee(self):
self.require_fee_update = True
def get_payto_or_dummy(self):
return self.payto_e.payto_address if self.payto_e.payto_address else self.wallet.dummy_address()
def do_update_fee(self):
'''Recalculate the fee. If the fee was manually input, retain it, but
still build the TX to see if there are enough funds.
'''
freeze_fee = (self.fee_e.isModified()
and (self.fee_e.text() or self.fee_e.hasFocus()))
outputs = self.payto_e.get_outputs()
amount = self.amount_e.get_amount()
if amount is None:
if not freeze_fee:
@ -1092,8 +1095,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
self.not_enough_funds = False
else:
fee = self.fee_e.get_amount() if freeze_fee else None
outputs = self.payto_e.get_outputs()
if not outputs:
addr = self.payto_e.payto_address if self.payto_e.payto_address else self.wallet.dummy_address()
addr = self.get_payto_or_dummy()
outputs = [(TYPE_ADDRESS, addr, amount)]
try:
tx = self.wallet.make_unsigned_transaction(self.get_coins(), outputs, self.config, fee)

View File

@ -657,12 +657,12 @@ class Abstract_Wallet(PrintError):
def dummy_address(self):
return self.addresses(False)[0]
def get_max_amount(self, config, inputs, fee):
def get_max_amount(self, config, inputs, recipient, fee):
sendable = sum(map(lambda x:x['value'], inputs))
for i in inputs:
self.add_input_info(i)
output = (TYPE_ADDRESS, self.dummy_address(), sendable)
dummy_tx = Transaction.from_io(inputs, [output])
outputs = [(TYPE_ADDRESS, recipient, sendable)]
dummy_tx = Transaction.from_io(inputs, outputs)
if fee is None:
fee = self.estimate_fee(config, dummy_tx.estimated_size())
amount = max(0, sendable - fee)