electrum

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

commit 2a3c97813d03d6ab877e8a0ae868b976abdf299d
parent 525e08af5405c5406ed1953d676d69dc7915c6af
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:
Mgui/kivy/main_window.py | 5+++++
Mgui/kivy/uix/ui_screens/amount.kv | 5+++--
Mgui/qt/main_window.py | 17+++--------------
Mlib/wallet.py | 13+++++++++++++
4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py @@ -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] diff --git a/gui/kivy/uix/ui_screens/amount.kv b/gui/kivy/uix/ui_screens/amount.kv @@ -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 diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -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) @@ -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 diff --git a/lib/wallet.py b/lib/wallet.py @@ -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))