def _read_wallet(self): self.address_bundle = [] if not os.path.isfile(self.wallet_dat_filename): upgraded = self._upgrade_old_wallet() if not upgraded: return try: logger.info('Retrieving wallet file') with open(self.wallet_dat_filename, "rb") as infile: wallet_store = qrl_pb2.WalletStore() wallet_store.ParseFromString(bytes(infile.read())) self.address_bundle = [] for a in wallet_store.wallets: tmpxmss = XMSS(config.dev.xmss_tree_height, mnemonic2bin(a.mnemonic.strip())) tmpxmss.set_index(a.xmss_index) if a.address != tmpxmss.get_address(): logger.fatal("Mnemonic and address do not match.") exit(1) self.address_bundle.append( AddressBundle(tmpxmss.get_address().encode(), tmpxmss)) except Exception as e: logger.warning("It was not possible to open the wallet: %s", e)
def save_wallet(self): logger.debug('Syncing wallet file') wallet_store = qrl_pb2.WalletStore() wallets = [] for a in self.address_bundle: wallets.append(qrl_pb2.Wallet(address=a.address, mnemonic=a.xmss.get_mnemonic(), xmss_index=a.xmss.get_index())) wallet_store.wallets.extend(wallets) with open(self.wallet_dat_filename, "wb") as outfile: outfile.write(wallet_store.SerializeToString())
def _read_wallet(self): self.address_bundle = [] if not os.path.isfile(self.wallet_dat_filename): return try: with open(self.wallet_dat_filename, "rb") as infile: wallet_store = qrl_pb2.WalletStore() wallet_store.ParseFromString(bytes(infile.read())) self.address_bundle = [] for a in wallet_store.wallets: tmpxmss = XMSS.from_extended_seed(mnemonic2bin(a.mnemonic.strip())) tmpxmss.set_ots_index(a.xmss_index) if a.address != bin2hstr(tmpxmss.address).encode(): logger.fatal("Mnemonic and address do not match.") exit(1) self.address_bundle.append(AddressBundle(a.address, tmpxmss)) except Exception as e: logger.warning("It was not possible to open the wallet: %s", e)