twallet.get_max_amount method, used by qt and kivy - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 2a3c97813d03d6ab877e8a0ae868b976abdf299d DIR parent 525e08af5405c5406ed1953d676d69dc7915c6af HTML Author: ThomasV <thomasv@electrum.org> Date: Fri, 30 Oct 2015 14:10:41 +0100 wallet.get_max_amount method, used by qt and kivy Diffstat: M gui/kivy/main_window.py | 5 +++++ M gui/kivy/uix/ui_screens/amount.kv | 5 +++-- M gui/qt/main_window.py | 17 +++-------------- M lib/wallet.py | 13 +++++++++++++ 4 files changed, 24 insertions(+), 16 deletions(-) --- DIR diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py t@@ -440,6 +440,11 @@ class ElectrumWindow(App): status_card.uncomfirmed = unconfirmed.strip() + def get_max_amount(self): + inputs = self.wallet.get_spendable_coins(None) + amount, fee = self.wallet.get_max_amount(self.electrum_config, inputs, None) + return self.format_amount(amount) + def update_amount(self, amount, c): if c == '<': return amount[:-1] DIR diff --git a/gui/kivy/uix/ui_screens/amount.kv b/gui/kivy/uix/ui_screens/amount.kv t@@ -22,8 +22,9 @@ Popup: Button: size_hint_x: 1 height: '48dp' - text: '' - on_release: a.value = "max" + amount: app.get_max_amount() + text: self.amount + ' ' + app.base_unit + on_release: a.amount = self.amount BoxLayout: size_hint: 1, None DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py t@@ -965,22 +965,15 @@ class ElectrumWindow(QMainWindow, PrintError): grid.addLayout(buttons, 6, 1, 1, 2) def on_shortcut(): - sendable = self.get_sendable_balance() inputs = self.get_coins() - for i in inputs: - self.wallet.add_input_info(i) - addr = self.payto_e.payto_address if self.payto_e.payto_address else self.dummy_address - output = ('address', addr, sendable) - dummy_tx = Transaction.from_io(inputs, [output]) + amount, fee = self.wallet.get_max_amount(self.config, inputs, self.fee_e.get_amount()) if self.fee_e.get_amount() is None: - fee_per_kb = self.wallet.fee_per_kb(self.config) - self.fee_e.setAmount(self.wallet.estimated_fee(dummy_tx, fee_per_kb)) - self.amount_e.setAmount(max(0, sendable - self.fee_e.get_amount())) + self.fee_e.setAmount(fee) + self.amount_e.setAmount(max(0, amount)) # emit signal for fiat_amount update self.amount_e.textEdited.emit("") self.amount_e.shortcut.connect(on_shortcut) - self.payto_e.textChanged.connect(self.update_fee) self.amount_e.textEdited.connect(self.update_fee) self.fee_e.textEdited.connect(self.update_fee) t@@ -1539,10 +1532,6 @@ class ElectrumWindow(QMainWindow, PrintError): menu.exec_(self.address_list.viewport().mapToGlobal(position)) - def get_sendable_balance(self): - return sum(map(lambda x:x['value'], self.get_coins())) - - def get_coins(self): if self.pay_from: return self.pay_from DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -633,6 +633,19 @@ class Abstract_Wallet(PrintError): coins = coins[1:] + [ coins[0] ] return [value for height, value in coins] + def get_max_amount(self, config, inputs, fee): + sendable = sum(map(lambda x:x['value'], inputs)) + for i in inputs: + self.add_input_info(i) + addr = self.addresses(False)[0] + output = ('address', addr, sendable) + dummy_tx = Transaction.from_io(inputs, [output]) + if fee is None: + fee_per_kb = self.fee_per_kb(config) + fee = self.estimated_fee(dummy_tx, fee_per_kb) + amount = max(0, sendable - fee) + return amount, fee + def get_account_name(self, k): return self.labels.get(k, self.accounts[k].get_name(k))