def test_state_loader(self): with set_data_dir('no_data'): alice_xmss = get_alice_xmss() state_loader = StateLoader(b'current_', db.DB()) self.assertEqual(state_loader.total_coin_supply, 0) state_loader.update_total_coin_supply(100) self.assertEqual(state_loader.total_coin_supply, 100) self.assertIsNone(state_loader.get_address(alice_xmss.address)) state_loader.add_address(alice_xmss.address) self.assertEqual(state_loader._data.addresses, [alice_xmss.address])
def state_migration_step_1(self, state: State) -> bool: """ Migration Step from State Version 0 to 1 :return: """ if state.is_older_state_version(): db_dir_v1 = os.path.join(config.user.data_dir, config.dev.db_name + '2') self._tmp_state = State(state._db) # DB Pointing to Older State state._db = db.DB(db_dir_v1) # DB Pointing to Newer State return True return False
def state_migration_step_2(self, state: State): """ Migration Step from State Version 0 to 1 :return: """ del self._tmp_state self._tmp_state = None del state._db tmp_db_dir = os.path.join(config.user.data_dir, config.dev.db_name + "3") db_dir = os.path.join(config.user.data_dir, config.dev.db_name) shutil.move(db_dir, tmp_db_dir) tmp_db_dir = os.path.join(config.user.data_dir, config.dev.db_name + "2") shutil.move(tmp_db_dir, db_dir) state._db = db.DB() logger.warning("State Migration Finished")
def __init__(self): self._db = db.DB() # generate db object here
def __init__(self): self._db = db.DB() # generate db object here self.state_objects = StateObjects(self._db)
def __init__(self, my_db=None): self._db = my_db if not my_db: self._db = db.DB() # generate db object here self._tmp_state = None # Temporary State file which needs to be fetched during migration to new db self._state_version = 1 # Change State Version, each time any change made to leveldb structure