commit 637164d33550c46354cdcf13991088545e14a4f6
parent 3d781a2d1b93d33b7232ba95b8f11e583e8ad436
Author: Neil Booth <kyuupichan@gmail.com>
Date: Sun, 10 Jan 2016 20:17:11 +0900
Introduce BIP32_RD_Wallet
Represents a BIP_32 wallet with a root derivation.
This permits us to see address derivation for NewWallet types
in the QT Gui.
Diffstat:
2 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -43,7 +43,7 @@ from electrum.util import PrintError, NotEnoughFunds, StoreDict
from electrum import Transaction, mnemonic
from electrum import util, bitcoin, commands
from electrum import SimpleConfig, COIN_CHOOSERS, paymentrequest
-from electrum.wallet import Wallet, BIP32_HD_Wallet
+from electrum.wallet import Wallet, BIP32_RD_Wallet
from amountedit import BTCAmountEdit, MyLineEdit, BTCkBEdit
from network_dialog import NetworkDialog
@@ -2030,7 +2030,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
d.setMinimumSize(600, 200)
vbox = QVBoxLayout()
vbox.addWidget( QLabel(_("Address") + ': ' + address))
- if isinstance(self.wallet, BIP32_HD_Wallet):
+ if isinstance(self.wallet, BIP32_RD_Wallet):
derivation = self.wallet.address_id(address)
vbox.addWidget(QLabel(_("Derivation") + ': ' + derivation))
vbox.addWidget(QLabel(_("Public key") + ':'))
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -1658,10 +1658,26 @@ class BIP32_Simple_Wallet(BIP32_Wallet):
self.add_master_public_key(self.root_name, xpub)
self.add_account('0', account)
+class BIP32_RD_Wallet(BIP32_Wallet):
+ # Abstract base class for a BIP32 wallet with a self.root_derivation
-class BIP32_HD_Wallet(BIP32_Wallet):
+ @classmethod
+ def account_derivation(self, account_id):
+ return self.root_derivation + account_id
+
+ @classmethod
+ def address_derivation(self, account_id, change, address_index):
+ account_derivation = self.account_derivation(account_id)
+ return "%s/%d/%d" % (account_derivation, change, address_index)
+
+ def address_id(self, address):
+ acc_id, (change, address_index) = self.get_address_index(address)
+ return self.address_derivation(acc_id, change, address_index)
+
+
+class BIP32_HD_Wallet(BIP32_RD_Wallet):
+ # Abstract base class for a BIP32 wallet that admits account creation
- # wallet that can create accounts
def __init__(self, storage):
BIP32_Wallet.__init__(self, storage)
# Backwards-compatibility. Remove legacy "next_account2" and
@@ -1726,24 +1742,15 @@ class BIP32_HD_Wallet(BIP32_Wallet):
def accounts_all_used(self):
return all(self.account_is_used(acc_id) for acc_id in self.accounts)
- @classmethod
- def account_derivation(self, account_id):
- return self.root_derivation + "/" + account_id + "'"
-
- @classmethod
- def address_derivation(self, account_id, change, address_index):
- account_derivation = self.account_derivation(account_id)
- return "%s/%d/%d" % (account_derivation, change, address_index)
-
- def address_id(self, address):
- acc_id, (change, address_index) = self.get_address_index(address)
- return self.address_derivation(acc_id, change, address_index)
-
class BIP44_Wallet(BIP32_HD_Wallet):
- root_derivation = "m/44'/0'"
+ root_derivation = "m/44'/0'/"
wallet_type = 'bip44'
+ @classmethod
+ def account_derivation(self, account_id):
+ return self.root_derivation + account_id + "'"
+
def can_sign_xpubkey(self, x_pubkey):
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
return xpub in self.master_public_keys.values()
@@ -1778,7 +1785,7 @@ class BIP44_Wallet(BIP32_HD_Wallet):
return xpub, None
-class NewWallet(BIP32_Wallet, Mnemonic):
+class NewWallet(BIP32_RD_Wallet, Mnemonic):
# Standard wallet
root_derivation = "m/"
wallet_type = 'standard'