electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit a3422d3fae78eaf901bf6e86ef120fc81c530e2b
parent 87709dfd16c270b721106f481c33c8c4583316ba
Author: ThomasV <thomasv@gitorious>
Date:   Fri,  3 Apr 2015 11:27:57 +0200

generic multisig wallet constructor. fixes #1129

Diffstat:
Melectrum | 5+----
Mgui/qt/installwizard.py | 95+++++--------------------------------------------------------------------------
Mlib/wallet.py | 32+++++++++++++++++++++++++++++++-
3 files changed, 38 insertions(+), 94 deletions(-)

diff --git a/electrum b/electrum @@ -334,10 +334,7 @@ if __name__ == '__main__': seed = getpass.getpass(prompt="seed:", stream=None) if options.concealed else raw_input("seed:") if not Wallet.is_seed(seed): sys.exit("Error: Invalid seed") - wallet = Wallet.from_seed(seed, storage) - wallet.add_seed(seed, password) - wallet.create_master_keys(password) - wallet.create_main_account(password) + wallet = Wallet.from_seed(seed, password, storage) if not options.offline: s = get_daemon(config, False) diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -439,99 +439,16 @@ class InstallWizard(QDialog): wallet = Wallet.from_private_key(text, password, self.storage) elif Wallet.is_seed(text): password = self.password_dialog() - wallet = Wallet.from_seed(text, self.storage) - wallet.add_seed(text, password) - wallet.create_master_keys(password) - wallet.create_main_account(password) + wallet = Wallet.from_seed(text, password, self.storage) else: raise BaseException('unknown wallet type') - elif t in ['2of2']: - r = self.multi_seed_dialog(1) - if not r: - return - text1, text2 = r - wallet = Wallet_2of2(self.storage) - if (Wallet.is_seed(text1) or Wallet.is_seed(text2) or - Wallet.is_xprv(text1) or Wallet.is_xprv(text2)): - password = self.password_dialog() - else: - password = None - - if (Wallet.is_seed(text2) or Wallet.is_xprv(text2)) and Wallet.is_xpub(text1): - c = text1 - text1 = text2 - text2 = c - - if Wallet.is_seed(text1): - wallet.add_seed(text1, password) - wallet.create_master_keys(password) - elif Wallet.is_xprv(text1): - xpub = bitcoin.xpub_from_xprv(text1) - wallet.add_master_public_key(wallet.root_name, xpub) - wallet.add_master_private_key(wallet.root_name, text1, password) - else: - wallet.add_master_public_key("x1/", text1) - - if Wallet.is_seed(text2): - wallet.add_cosigner_seed(text2, "x2/", password) - elif Wallet.is_xpub(text2): - wallet.add_master_public_key("x2/", text2) - - wallet.create_main_account(password) - - - elif t in ['2of3']: - r = self.multi_seed_dialog(2) - if not r: + elif t in ['2of2', '2of3']: + key_list = self.multi_seed_dialog(1 if t == '2of2' else 2) + if not key_list: return - text1, text2, text3 = r - wallet = Wallet_2of3(self.storage) - if (Wallet.is_seed(text1) or Wallet.is_seed(text2) or Wallet.is_seed(text3) or - Wallet.is_xprv(text1) or Wallet.is_xprv(text2) or Wallet.is_xprv(text3)): - password = self.password_dialog() - else: - password = None - - if Wallet.is_xpub(text1) and (Wallet.is_seed(text2) or Wallet.is_xprv(text2)): - temp = text1 - text1 = text2 - text2 = temp - - if Wallet.is_xpub(text1) and (Wallet.is_seed(text3) or Wallet.is_xprv(text3)): - temp = text1 - text1 = text3 - text3 = temp - - if Wallet.is_seed(text1): - wallet.add_seed(text1, password) - wallet.create_master_keys(password) - elif Wallet.is_xprv(text1): - xpub = bitcoin.xpub_from_xprv(text1) - wallet.add_master_public_key(wallet.root_name, xpub) - wallet.add_master_private_key(wallet.root_name, text1, password) - else: - wallet.add_master_public_key("x1/", text1) - - if Wallet.is_seed(text2): - wallet.add_cosigner_seed(text2, "x2/", password) - elif Wallet.is_xprv(text2): - xpub = bitcoin.xpub_from_xprv(text2) - wallet.add_master_public_key(wallet.root_name, xpub) - wallet.add_master_private_key(wallet.root_name, text2, password) - elif Wallet.is_xpub(text2): - wallet.add_master_public_key("x2/", text2) - - if Wallet.is_seed(text3): - wallet.add_cosigner_seed(text3, "x3/", password) - elif Wallet.is_xprv(text3): - xpub = bitcoin.xpub_from_xprv(text3) - wallet.add_master_public_key(wallet.root_name, xpub) - wallet.add_master_private_key(wallet.root_name, text3, password) - elif Wallet.is_xpub(text3): - wallet.add_master_public_key("x3/", text3) - - wallet.create_main_account(password) + password = self.password_dialog() if any(map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x), key_list)) else None + wallet = Wallet.from_multisig(key_list, password, self.storage) else: self.storage.put('wallet_type', t) diff --git a/lib/wallet.py b/lib/wallet.py @@ -1798,12 +1798,15 @@ class Wallet(object): return True @classmethod - def from_seed(self, seed, storage): + def from_seed(self, seed, password, storage): if is_old_seed(seed): klass = OldWallet elif is_new_seed(seed): klass = NewWallet w = klass(storage) + w.add_seed(text, password) + w.create_master_keys(password) + w.create_main_account(password) return w @classmethod @@ -1840,3 +1843,30 @@ class Wallet(object): w = BIP32_Simple_Wallet(storage) w.create_xprv_wallet(xprv, password) return w + + @classmethod + def from_multisig(klass, key_list, password, storage): + if len(key_list) == 2: + self = Wallet_2of2(storage) + elif len(key_list) == 3: + self = Wallet_2of3(storage) + key_list = sorted(key_list, key = lambda x: klass.is_xpub(x)) + for i, text in enumerate(key_list): + assert klass.is_seed(text) or klass.is_xprv(text) or klass.is_xpub(text) + name = "x%d/"%(i+1) + if klass.is_seed(text): + if name == 'x1/': + self.add_seed(text1, password) + self.create_master_keys(password) + else: + self.add_cosigner_seed(text, name, password) + elif klass.is_xprv(text): + xpub = bitcoin.xpub_from_xprv(text) + self.add_master_public_key(name, xpub) + self.add_master_private_key(name, text, password) + elif klass.is_xpub(text): + self.add_master_public_key(name, text) + self.use_encryption = (password != None) + self.storage.put('use_encryption', self.use_encryption, True) + self.create_main_account(password) + return self