def new_account_dialog(self):
- text, ok = QInputDialog.getText(self, _('New Account'), _('Name') + ':')
- if not ok or not text:
- return
- name = unicode(text)
- try:
- self.create_new_account(name)
- except:
- QMessageBox.warning(self, _('Error'), _('Incorrect Password'), _('OK'))
+
+ dialog = QDialog(self)
+ dialog.setModal(1)
+ dialog.setWindowTitle(_("New Account"))
+
+ addr = self.wallet.new_account_address()
+ vbox = QVBoxLayout()
+ vbox.addWidget(QLabel("To add another account, please send bitcoins to the following address:"))
+ e = QLineEdit(addr)
+ e.setReadOnly(True)
+ vbox.addWidget(e)
+
+ ok_button = QPushButton(_("OK"))
+ ok_button.setDefault(True)
+ ok_button.clicked.connect(dialog.accept)
+
+ hbox = QHBoxLayout()
+ hbox.addStretch(1)
+ hbox.addWidget(ok_button)
+ vbox.addLayout(hbox)
+
+ dialog.setLayout(vbox)
+ dialog.exec_()
+
- @protected
- def create_new_account(self, name, password):
- self.wallet.create_new_account(name, password)
- self.wallet.synchronize()
- self.update_receive_tab()
- self.update_history_tab()
- self.update_completions()
def show_master_public_key(self):
dialog = QDialog(self)
self.master_public_keys = config.get('master_public_keys',{})
self.master_private_keys = config.get('master_private_keys', {})
+ self.first_addresses = config.get('first_addresses',{})
+
self.load_accounts(config)
self.transactions = {}
self.config.set_key('master_private_keys', self.master_private_keys, True)
# create default account
- self.create_account('Main account')
+ self.create_account('1','Main account')
def find_root_by_master_key(self, c, K):
def account_id(self, account_type, i):
- if account_type is None:
+ if account_type == '1':
return "m/0'/%d"%i
elif account_type == '2of2':
return "m/1'/%d & m/2'/%d"%(i,i)
return i
- def create_account(self, name, account_type = None):
+ def new_account_address(self, account_type = '1'):
+ i = self.num_accounts(account_type)
+ k = self.account_id(account_type,i)
+
+ addr = self.first_addresses.get(k)
+ if not addr:
+ account_id, account = self.next_account(account_type)
+ addr = account.first_address()
+ self.first_addresses[k] = addr
+ self.config.set_key('first_addresses',self.first_addresses)
+
+ return addr
+
+
+ def next_account(self, account_type = '1'):
+
i = self.num_accounts(account_type)
account_id = self.account_id(account_type,i)
- if account_type is None:
+ if account_type is '1':
master_c0, master_K0, _ = self.master_public_keys["m/0'/"]
c0, K0, cK0 = bip32_public_derivation(master_c0.decode('hex'), master_K0.decode('hex'), "m/0'/", "m/0'/%d"%i)
account = BIP32_Account({ 'c':c0, 'K':K0, 'cK':cK0 })
c5, K5, cK5 = bip32_public_derivation(master_c5.decode('hex'), master_K5.decode('hex'), "m/5'/", "m/5'/%d"%i)
account = BIP32_Account_2of3({ 'c':c3, 'K':K3, 'cK':cK3, 'c2':c4, 'K2':K4, 'cK2':cK4, 'c3':c5, 'K3':K5, 'cK3':cK5 })
+ return account_id, account
+
+
+ def create_account(self, account_type = '1', name = 'unnamed'):
+ account_id, account = self.next_account(account_type)
self.accounts[account_id] = account
self.save_accounts()
self.labels[account_id] = name
self.accounts[k] = BIP32_Account(v)
-
-
def addresses(self, include_change = True):
o = self.get_account_addresses(-1, include_change)
for a in self.accounts.keys():
def is_mine(self, address):
return address in self.addresses(True)
+
def is_change(self, address):
if not self.is_mine(address): return False
if address in self.imported_keys.keys(): return False
return new_addresses
+
+ def create_pending_accounts(self):
+
+ for account_type in ['1','2of2','2of3']:
+ a = self.new_account_address(account_type)
+ if self.address_is_old(a):
+ print "creating account", a
+ self.create_account(account_type)
+
+
def synchronize_account(self, account):
new = []
new += self.synchronize_sequence(account, 0)
new += self.synchronize_sequence(account, 1)
return new
+
def synchronize(self):
+ self.create_pending_accounts()
new = []
for account in self.accounts.values():
new += self.synchronize_account(account)