def update_receive_tab(self):
l = self.receive_list
+ # extend the syntax for consistency
+ l.addChild = l.addTopLevelItem
l.clear()
- l.setColumnHidden(2, False)
- l.setColumnHidden(3, False)
for i,width in enumerate(self.column_widths['receive']):
l.setColumnWidth(i, width)
+ accounts = self.wallet.get_accounts()
if self.current_account is None:
- account_items = sorted(self.wallet.accounts.items())
- elif self.current_account != -1:
- account_items = [(self.current_account, self.wallet.accounts.get(self.current_account))]
+ account_items = sorted(accounts.items())
else:
- account_items = []
+ account_items = [(self.current_account, accounts.get(self.current_account))]
- pending_accounts = self.wallet.get_pending_accounts()
for k, account in account_items:
- if len(account_items) + len(pending_accounts) > 1:
+ if len(accounts) > 1:
name = self.wallet.get_account_name(k)
c,u = self.wallet.get_account_balance(k)
account_item = QTreeWidgetItem( [ name, '', self.format_amount(c+u), ''] )
account_item.setExpanded(self.accounts_expanded.get(k, True))
account_item.setData(0, 32, k)
else:
- account_item = None
+ account_item = l
- for is_change in ([0,1]):
- name = _("Receiving") if not is_change else _("Change")
- seq_item = QTreeWidgetItem( [ name, '', '', '', ''] )
- if account_item:
+ sequences = [0,1] if account.has_change() else [0]
+ for is_change in sequences:
+ if len(sequences) > 1:
+ name = _("Receiving") if not is_change else _("Change")
+ seq_item = QTreeWidgetItem( [ name, '', '', '', ''] )
account_item.addChild(seq_item)
+ if not is_change:
+ seq_item.setExpanded(True)
else:
- l.addTopLevelItem(seq_item)
+ seq_item = account_item
used_item = QTreeWidgetItem( [ _("Used"), '', '', '', ''] )
used_flag = False
- if not is_change: seq_item.setExpanded(True)
is_red = False
gap = 0
c, u = self.wallet.get_addr_balance(address)
num_tx = '*' if h == ['*'] else "%d"%len(h)
+
item = QTreeWidgetItem( [ address, '', '', num_tx] )
self.update_receive_item(item)
if is_red:
else:
seq_item.addChild(item)
-
- for k, addr in pending_accounts:
- name = self.wallet.labels.get(k,'')
- account_item = QTreeWidgetItem( [ name + " [ "+_('pending account')+" ]", '', '', ''] )
- self.update_receive_item(item)
- l.addTopLevelItem(account_item)
- account_item.setExpanded(True)
- account_item.setData(0, 32, k)
- item = QTreeWidgetItem( [ addr, '', '', '', ''] )
- account_item.addChild(item)
- self.update_receive_item(item)
-
-
- if self.wallet.imported_keys and (self.current_account is None or self.current_account == -1):
- c,u = self.wallet.get_imported_balance()
- account_item = QTreeWidgetItem( [ _('Imported'), '', self.format_amount(c+u), ''] )
- l.addTopLevelItem(account_item)
- account_item.setExpanded(True)
- for address in self.wallet.imported_keys.keys():
- item = QTreeWidgetItem( [ address, '', '', ''] )
- self.update_receive_item(item)
- account_item.addChild(item)
-
-
# we use column 1 because column 0 may be hidden
l.setCurrentItem(l.topLevelItem(0),1)
self.addressbook = storage.get('contacts', [])
self.imported_keys = storage.get('imported_keys',{})
+ self.imported_account = ImportedAccount(self.imported_keys)
+
self.history = storage.get('addr_history',{}) # address -> list(txid, height)
self.fee = int(storage.get('fee_per_kb', 10000))
def synchronize(self):
pass
- def get_pending_accounts(self):
- return {}
-
def can_create_accounts(self):
return False
def is_mine(self, address):
- return address in self.addresses(True)
+ return address in self.addresses(True)
def is_change(self, address):
def get_addr_balance(self, address):
- assert self.is_mine(address)
+ #assert self.is_mine(address)
h = self.history.get(address,[])
if h == ['*']: return 0,0
c = u = 0
o = self.addresses(True)
elif a == -1:
o = self.imported_keys.keys()
- else:
+ elif a in self.accounts:
ac = self.accounts[a]
o = ac.get_addresses(0)
if include_change: o += ac.get_addresses(1)
address = address_from_private_key(sec)
assert address == k
+ def get_accounts(self):
+ return { -1:self.imported_account }
+
+
class Deterministic_Wallet(Abstract_Wallet):
self.check_pending_accounts()
new = []
for account in self.accounts.values():
+ if type(account) == PendingAccount:
+ continue
new += self.synchronize_account(account)
if new:
self.save_accounts()
def add_account(self, account_id, account):
self.accounts[account_id] = account
- if account_id in self.pending_accounts:
- self.pending_accounts.pop(account_id)
- self.storage.put('pending_accounts', self.pending_accounts)
self.save_accounts()
self.accounts[k] = BIP32_Account_2of2(v)
elif v.get('xpub'):
self.accounts[k] = BIP32_Account(v)
+ elif v.get('pending'):
+ self.accounts[k] = PendingAccount(v)
else:
raise
- self.pending_accounts = self.storage.get('pending_accounts',{})
-
-
def delete_pending_account(self, k):
- self.pending_accounts.pop(k)
- self.storage.put('pending_accounts', self.pending_accounts)
+ assert self.is_pending_account(k)
+ self.accounts.pop(k)
+ self.save_accounts()
def account_is_pending(self, k):
- return k in self.pending_accounts
+ return type(self.accounts.get(k)) == PendingAccount
def create_pending_account(self, name, password):
account_id, addr = self.next_account_address(password)
self.set_label(account_id, name)
- self.pending_accounts[account_id] = addr
- self.storage.put('pending_accounts', self.pending_accounts)
+ self.accounts[account_id] = PendingAccount({'pending':addr})
+ self.save_accounts()
- def get_pending_accounts(self):
- return self.pending_accounts.items()
+ def get_accounts(self):
+ out = sorted(self.accounts.items())
+ if self.imported_keys:
+ out.append( (-1, self.imported_account ))
+ return dict(out)
def get_account_name(self, k):
- assert k == 0
- return 'Main account'
+ if k == 0:
+ return 'Main account'
+ elif k == -1:
+ return 'Imported'
def get_private_key(self, address, password):