Browse Source

wallet.is_beyond_limit (False for imported accounts)

283
ThomasV 11 years ago
parent
commit
0c440ee6a6
  1. 50
      gui/qt/main_window.py
  2. 18
      lib/wallet.py

50
gui/qt/main_window.py

@ -1491,24 +1491,6 @@ class ElectrumWindow(QMainWindow):
menu.exec_(self.invoices_list.viewport().mapToGlobal(position)) menu.exec_(self.invoices_list.viewport().mapToGlobal(position))
def update_address_item(self, item):
item.setFont(0, QFont(MONOSPACE_FONT))
address = str(item.data(0,0).toString())
label = self.wallet.labels.get(address,'')
item.setData(1,0,label)
item.setData(0,32, True) # is editable
run_hook('update_address_item', address, item)
if not self.wallet.is_mine(address): return
c, u = self.wallet.get_addr_balance(address)
balance = self.format_amount(c + u)
item.setData(2,0,balance)
if address in self.wallet.frozen_addresses:
item.setBackgroundColor(0, QColor('lightblue'))
def update_address_tab(self): def update_address_tab(self):
l = self.address_list l = self.address_list
@ -1551,27 +1533,22 @@ class ElectrumWindow(QMainWindow):
used_item = QTreeWidgetItem( [ _("Used"), '', '', '', ''] ) used_item = QTreeWidgetItem( [ _("Used"), '', '', '', ''] )
used_flag = False used_flag = False
is_red = False addr_list = account.get_addresses(is_change)
gap = 0 for address in addr_list:
for address in account.get_addresses(is_change):
num, is_used = self.wallet.is_used(address) num, is_used = self.wallet.is_used(address)
if num == 0: label = self.wallet.labels.get(address,'')
gap += 1 c, u = self.wallet.get_addr_balance(address)
if gap > self.wallet.gap_limit: balance = self.format_amount(c + u)
is_red = True item = QTreeWidgetItem( [ address, label, balance, "%d"%num] )
else: item.setFont(0, QFont(MONOSPACE_FONT))
gap = 0 item.setData(0, 32, True) # label can be edited
if address in self.wallet.frozen_addresses:
item = QTreeWidgetItem( [ address, '', '', "%d"%num] ) item.setBackgroundColor(0, QColor('lightblue'))
self.update_address_item(item) if self.wallet.is_beyond_limit(address, account, is_change):
if is_red: item.setBackgroundColor(0, QColor('red'))
item.setBackgroundColor(1, QColor('red'))
if is_used: if is_used:
if not used_flag: if not used_flag:
seq_item.insertChild(0,used_item) seq_item.insertChild(0, used_item)
used_flag = True used_flag = True
used_item.addChild(item) used_item.addChild(item)
else: else:
@ -1600,7 +1577,6 @@ class ElectrumWindow(QMainWindow):
l.setCurrentItem(l.topLevelItem(0)) l.setCurrentItem(l.topLevelItem(0))
def create_console_tab(self): def create_console_tab(self):
from console import Console from console import Console
self.console = console = Console() self.console = console = Console()

18
lib/wallet.py

@ -1051,6 +1051,8 @@ class Imported_Wallet(Abstract_Wallet):
def get_master_public_keys(self): def get_master_public_keys(self):
return {} return {}
def is_beyond_limit(self, address, account, is_change):
return False
class Deterministic_Wallet(Abstract_Wallet): class Deterministic_Wallet(Abstract_Wallet):
@ -1239,6 +1241,22 @@ class Deterministic_Wallet(Abstract_Wallet):
self.accounts[account_id] = PendingAccount({'pending':addr}) self.accounts[account_id] = PendingAccount({'pending':addr})
self.save_accounts() self.save_accounts()
def is_beyond_limit(self, address, account, is_change):
if type(account) == ImportedAccount:
return False
addr_list = account.get_addresses(is_change)
i = addr_list.index(address)
prev_addresses = addr_list[:max(0, i)]
limit = self.gap_limit_for_change if is_change else self.gap_limit
if len(prev_addresses) < limit:
return False
prev_addresses = prev_addresses[max(0, i - limit):]
for addr in prev_addresses:
num, is_used = self.is_used(addr)
if num > 0:
return False
return True
class NewWallet(Deterministic_Wallet): class NewWallet(Deterministic_Wallet):

Loading…
Cancel
Save