commit a9d341ec9c5d8fe48d3a8c718e6c41e9183f0a71
parent 4652783cfd015d93c848d4c5e94406e28edd6cbc
Author: thomasv <thomasv@gitorious>
Date: Sat, 12 Oct 2013 13:55:48 +0200
move pending accounts logic into wallet.py
Diffstat:
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -270,7 +270,6 @@ class ElectrumWindow(QMainWindow):
self.wallet = wallet
self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{})
self.current_account = self.wallet.storage.get("current_account", None)
- self.pending_accounts = self.wallet.storage.get('pending_accounts',{})
title = 'Electrum ' + self.wallet.electrum_version + ' - ' + self.wallet.storage.path
if self.wallet.is_watching_only(): title += ' [%s]' % (_('watching only'))
@@ -1093,13 +1092,12 @@ class ElectrumWindow(QMainWindow):
menu.addAction(_("Maximize"), lambda: self.account_set_expanded(item, k, True))
menu.addAction(_("Rename"), lambda: self.edit_account_label(k))
menu.addAction(_("View details"), lambda: self.show_account_details(k))
- if k in self.pending_accounts:
+ if self.wallet.account_is_pending(k):
menu.addAction(_("Delete"), lambda: self.delete_pending_account(k))
menu.exec_(self.receive_list.viewport().mapToGlobal(position))
def delete_pending_account(self, k):
- self.pending_accounts.pop(k)
- self.wallet.storage.put('pending_accounts', self.pending_accounts)
+ self.wallet.delete_pending_account(k)
self.update_receive_tab()
def create_receive_menu(self, position):
@@ -1250,10 +1248,7 @@ class ElectrumWindow(QMainWindow):
seq_item.addChild(item)
- for k, addr in self.pending_accounts.items():
- if k in self.wallet.accounts:
- self.pending_accounts.pop(k)
- self.wallet.storage.put('pending_accounts', self.pending_accounts)
+ for k, addr in self.wallet.get_pending_accounts():
name = self.wallet.labels.get(k,'')
account_item = QTreeWidgetItem( [ name + " [ "+_('pending account')+" ]", '', '', ''] )
self.update_receive_item(item)
@@ -1455,10 +1450,7 @@ class ElectrumWindow(QMainWindow):
name = str(e.text())
if not name: return
- k, addr = self.wallet.new_account_address()
- self.wallet.set_label(k, name)
- self.pending_accounts[k] = addr
- self.wallet.storage.put('pending_accounts', self.pending_accounts)
+ self.wallet.create_pending_account('1', name)
self.update_receive_tab()
self.tabs.setCurrentIndex(2)
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -425,11 +425,15 @@ class Wallet:
def create_account(self, account_type = '1', name = None):
- account_id, account = self.next_account(account_type)
- self.accounts[account_id] = account
+ k, account = self.next_account(account_type)
+ if k in self.pending_accounts:
+ self.pending_accounts.pop(k)
+ self.storage.put('pending_accounts', self.pending_accounts)
+
+ self.accounts[k] = account
self.save_accounts()
if name:
- self.set_label(account_id, name)
+ self.set_label(k, name)
def create_old_account(self):
@@ -459,6 +463,25 @@ class Wallet:
else:
self.accounts[k] = BIP32_Account(v)
+ 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)
+
+ def account_is_pending(self, k):
+ return k in self.pending_accounts
+
+ def create_pending_account(self, acct_type, name):
+ k, addr = self.new_account_address(acct_type)
+ self.set_label(k, name)
+ self.pending_accounts[k] = addr
+ self.storage.put('pending_accounts', self.pending_accounts)
+
+ def get_pending_accounts(self):
+ return self.pending_accounts.items()
+
def addresses(self, include_change = True, _next=True):
o = self.get_account_addresses(-1, include_change)