Browse Source

wallet.get_max_amount method, used by qt and kivy

283
ThomasV 9 years ago
parent
commit
2a3c97813d
  1. 5
      gui/kivy/main_window.py
  2. 5
      gui/kivy/uix/ui_screens/amount.kv
  3. 17
      gui/qt/main_window.py
  4. 13
      lib/wallet.py

5
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]

5
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

17
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

13
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))

Loading…
Cancel
Save