Browse Source

get_master_public_keys

283
ThomasV 11 years ago
parent
commit
a1daba6afe
  1. 70
      gui/qt/main_window.py
  2. 2
      lib/commands.py
  3. 23
      lib/wallet.py

70
gui/qt/main_window.py

@ -353,7 +353,7 @@ class ElectrumWindow(QMainWindow):
wallet_menu.addAction(_("&Password"), self.change_password_dialog)
wallet_menu.addAction(_("&Seed"), self.show_seed_dialog)
wallet_menu.addAction(_("&Master Public Key"), self.show_master_public_key)
wallet_menu.addAction(_("&Master Public Keys"), self.show_master_public_keys)
wallet_menu.addSeparator()
labels_menu = wallet_menu.addMenu(_("&Labels"))
@ -1524,70 +1524,24 @@ class ElectrumWindow(QMainWindow):
def show_master_public_key_old(self):
dialog = QDialog(self)
dialog.setModal(1)
dialog.setWindowTitle(_("Master Public Key"))
main_text = QTextEdit()
main_text.setText(self.wallet.get_master_public_key())
main_text.setReadOnly(True)
main_text.setMaximumHeight(170)
qrw = QRCodeWidget(self.wallet.get_master_public_key())
ok_button = QPushButton(_("OK"))
ok_button.setDefault(True)
ok_button.clicked.connect(dialog.accept)
main_layout = QGridLayout()
main_layout.addWidget(QLabel(_('Your Master Public Key is:')), 0, 0, 1, 2)
main_layout.addWidget(main_text, 1, 0)
main_layout.addWidget(qrw, 1, 1 )
vbox = QVBoxLayout()
vbox.addLayout(main_layout)
vbox.addLayout(close_button(dialog))
dialog.setLayout(vbox)
dialog.exec_()
def show_master_public_key(self):
if self.wallet.seed_version == 4:
self.show_master_public_key_old()
return
def show_master_public_keys(self):
dialog = QDialog(self)
dialog.setModal(1)
dialog.setWindowTitle(_("Master Public Keys"))
mpk_text = QTextEdit()
mpk_text.setReadOnly(True)
mpk_text.setMaximumHeight(170)
mpk_qrw = QRCodeWidget()
main_layout = QGridLayout()
main_layout.addWidget(QLabel(_('Key')), 1, 0)
main_layout.addWidget(mpk_text, 1, 1)
main_layout.addWidget(mpk_qrw, 1, 2)
def update(key):
xpub = self.wallet.master_public_keys[str(key)]
mpk_text.setText(xpub)
mpk_qrw.set_addr(xpub)
mpk_qrw.update_qr()
key_selector = QComboBox()
keys = sorted(self.wallet.master_public_keys.keys())
key_selector.addItems(keys)
main_layout.addWidget(QLabel(_('Derivation:')), 0, 0)
main_layout.addWidget(key_selector, 0, 1)
dialog.connect(key_selector,SIGNAL("activated(QString)"),update)
update(keys[0])
mpk_dict = self.wallet.get_master_public_keys()
i = 0
for key, value in mpk_dict.items():
main_layout.addWidget(QLabel(key), i, 0)
mpk_text = QTextEdit()
mpk_text.setReadOnly(True)
mpk_text.setMaximumHeight(170)
mpk_text.setText(value)
main_layout.addWidget(mpk_text, i + 1, 0)
i += 2
vbox = QVBoxLayout()
vbox.addLayout(main_layout)

2
lib/commands.py

@ -247,7 +247,7 @@ class Commands:
return electrum.ELECTRUM_VERSION
def getmpk(self):
return self.wallet.get_master_public_key()
return self.wallet.get_master_public_keys()
def getseed(self):
mnemonic = self.wallet.get_mnemonic(self.password)

23
lib/wallet.py

@ -519,8 +519,13 @@ class NewWallet:
if s is None: return False
return s[0] == 1
def get_master_public_key(self):
return self.storage.get("master_public_keys")["m/"]
def get_master_public_keys(self):
out = {}
for k, account in self.accounts.items():
name = self.get_account_name(k)
mpk_text = '\n\n'.join( account.get_master_pubkeys() )
out[name] = mpk_text
return out
def get_master_private_key(self, account, password):
k = self.master_private_keys.get(account)
@ -1497,6 +1502,10 @@ class Wallet_2of2(NewWallet):
account = BIP32_Account_2of2({'xpub':xpub1, 'xpub2':xpub2})
self.add_account('m/', account)
def get_master_public_keys(self):
xpub1 = self.master_public_keys.get("m/")
xpub2 = self.master_public_keys.get("cold/")
return {'hot':xpub1, 'cold':xpub2}
class Wallet_2of3(Wallet_2of2):
@ -1511,6 +1520,11 @@ class Wallet_2of3(Wallet_2of2):
account = BIP32_Account_2of3({'xpub':xpub1, 'xpub2':xpub2, 'xpub3':xpub3})
self.add_account('m/', account)
def get_master_public_keys(self):
xpub1 = self.master_public_keys.get("m/")
xpub2 = self.master_public_keys.get("cold/")
xpub3 = self.master_public_keys.get("remote/")
return {'hot':xpub1, 'cold':xpub2, 'remote':xpub3}
class WalletSynchronizer(threading.Thread):
@ -1720,8 +1734,9 @@ class OldWallet(NewWallet):
mpk = OldAccount.mpk_from_seed(seed)
self.storage.put('master_public_key', mpk, True)
def get_master_public_key(self):
return self.storage.get("master_public_key")
def get_master_public_keys(self):
mpk = self.storage.get("master_public_key")
return {'Main Account':mpk}
def create_accounts(self, password):
mpk = self.get_master_public_key()

Loading…
Cancel
Save