move pending accounts logic into wallet.py
authorthomasv <thomasv@gitorious>
Sat, 12 Oct 2013 11:55:48 +0000 (13:55 +0200)
committerthomasv <thomasv@gitorious>
Sat, 12 Oct 2013 11:55:48 +0000 (13:55 +0200)
gui/qt/main_window.py
lib/wallet.py

index 68f51f9..409984f 100644 (file)
@@ -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)
         
index 5af5765..f361f41 100644 (file)
@@ -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)