def on_keystore(self, k): has_xpub = isinstance(k, keystore.Xpub) if has_xpub: from lib.bitcoin import xpub_type t1 = xpub_type(k.xpub) if self.wallet_type == 'standard': if has_xpub and t1 not in ['standard']: self.show_error(_('Wrong key type') + ' %s' % t1) self.run('choose_keystore') return self.keystores.append(k) self.run('create_wallet') elif self.wallet_type == 'multisig': assert has_xpub if t1 not in ['standard']: self.show_error(_('Wrong key type') + ' %s' % t1) self.run('choose_keystore') return if k.xpub in map(lambda x: x.xpub, self.keystores): self.show_error(_('Error: duplicate master public key')) self.run('choose_keystore') return if len(self.keystores) > 0: t2 = xpub_type(self.keystores[0].xpub) if t1 != t2: self.show_error( _('Cannot add this cosigner:') + '\n' + "Their key type is '%s', we are '%s'" % (t1, t2)) self.run('choose_keystore') return self.keystores.append(k) if len(self.keystores) == 1: xpub = k.get_master_public_key() self.stack = [] self.run('show_xpub_and_add_cosigners', xpub) elif len(self.keystores) < self.n: self.run('choose_keystore') else: self.run('create_wallet')
def test_xpub_type(self): for xprv_details in self.xprv_xpub: xpub = xprv_details['xpub'] self.assertEqual(xprv_details['xtype'], xpub_type(xpub))