def migrate_genesis_txn(base_dir): for suffix in ('sandbox', 'live', 'local'): old_domain_genesis = os.path.join( base_dir, 'transactions_{}'.format(suffix)) old_pool_genesis = os.path.join( base_dir, 'pool_transactions_{}'.format(suffix)) new_domain_genesis = os.path.join( base_dir, 'domain_transactions_{}_genesis'.format(suffix)) new_pool_genesis = os.path.join( base_dir, 'pool_transactions_{}_genesis'.format(suffix)) if os.path.exists(old_domain_genesis): os.remove(old_domain_genesis) if os.path.exists(old_pool_genesis): os.remove(old_pool_genesis) if os.path.exists(new_domain_genesis): old_ser = CompactSerializer(getTxnOrderedFields()) new_ser = JsonSerializer() with open(new_domain_genesis, 'r') as f1: with open(old_domain_genesis, 'w') as f2: for line in store_utils.cleanLines(f1): txn = new_ser.deserialize(line) txn = old_ser.serialize(txn) f2.write(txn) os.remove(new_domain_genesis) if os.path.exists(new_pool_genesis): os.rename(new_pool_genesis, old_domain_genesis)
def migrate_genesis_txn(base_dir): for suffix in ('sandbox', 'live', 'local'): old_domain_genesis = os.path.join( base_dir, 'transactions_{}'.format(suffix)) old_pool_genesis = os.path.join( base_dir, 'pool_transactions_{}'.format(suffix)) new_domain_genesis = os.path.join( base_dir, 'domain_transactions_{}_genesis'.format(suffix)) new_pool_genesis = os.path.join( base_dir, 'pool_transactions_{}_genesis'.format(suffix)) if os.path.exists(old_domain_genesis): os.remove(old_domain_genesis) if os.path.exists(old_pool_genesis): os.remove(old_pool_genesis) if os.path.exists(new_domain_genesis): old_ser = CompactSerializer(getTxnOrderedFields()) new_ser = JsonSerializer() with open(new_domain_genesis, 'r') as f1: with open(old_domain_genesis, 'w') as f2: for line in store_utils.cleanLines(f1): txn = new_ser.deserialize(line) txn = old_ser.serialize(txn) f2.write(txn) os.remove(new_domain_genesis) if os.path.exists(new_pool_genesis): os.rename(new_pool_genesis, old_domain_genesis)
def init_ledger_from_genesis_txn(self, ledger: Ledger): # TODO: it's possible that the file to be used for initialization does not exist. # This is not considered as an error as of now. init_file = os.path.join(self.__data_dir, self.__db_name) if not os.path.exists(init_file): logger.display("File that should be used for initialization of " "Ledger does not exist: {}".format(init_file)) return with open(init_file, 'r') as f: for line in store_utils.cleanLines(f): txn = self.__serializer.deserialize(line) ledger.add(txn)
def test_genesis_txn_file_initiator(tempdir, init_genesis_txn_file, genesis_txns): # Check that initiator of genesis txns work: # It uses a text file with JsonSerializer by default genesis_file = genesis_txn_file( os.path.join(tempdir, init_genesis_txn_file)) assert os.path.exists(genesis_file) i = 0 serializer = JsonSerializer() with open(genesis_file) as f: for line in store_utils.cleanLines(f.readlines()): assert sorted(serializer.deserialize(line).items() ) == sorted(genesis_txns[i].items()) i += 1
def test_genesis_txn_file_initiator(tempdir, init_genesis_txn_file, genesis_txns): # Check that initiator of genesis txns work: # It uses a text file with JsonSerializer by default genesis_file = genesis_txn_file( os.path.join(tempdir, init_genesis_txn_file)) assert os.path.exists(genesis_file) i = 0 serializer = JsonSerializer() with open(genesis_file) as f: for line in store_utils.cleanLines(f.readlines()): assert sorted(serializer.deserialize(line).items() ) == sorted(genesis_txns[i].items()) i += 1
def test_pool_genesis_txns(bootstrap, pool_genesis_file): serializer = JsonSerializer() with open(pool_genesis_file) as f: for line in store_utils.cleanLines(f.readlines()): txn = serializer.deserialize(line) assert get_seq_no(txn) assert get_txn_id(txn) assert get_payload_data(txn) assert get_type(txn) == NODE assert get_version(txn) == "1" assert get_payload_data(txn)[TARGET_NYM] data = get_payload_data(txn).get(DATA) assert data assert data[ALIAS] assert data[CLIENT_IP] assert data[CLIENT_PORT] assert data[NODE_IP] assert data[NODE_PORT] assert data[SERVICES] == [VALIDATOR] assert data[BLS_KEY]
def test_pool_genesis_txns(bootstrap, pool_genesis_file): serializer = JsonSerializer() with open(pool_genesis_file) as f: for line in store_utils.cleanLines(f.readlines()): txn = serializer.deserialize(line) assert get_seq_no(txn) assert get_txn_id(txn) assert get_payload_data(txn) assert get_type(txn) == NODE assert get_version(txn) == "1" assert get_protocol_version(txn) is None assert get_payload_data(txn)[TARGET_NYM] data = get_payload_data(txn).get(DATA) assert data assert data[ALIAS] assert data[CLIENT_IP] assert data[CLIENT_PORT] assert data[NODE_IP] assert data[NODE_PORT] assert data[SERVICES] == [VALIDATOR] assert data[BLS_KEY] assert data[BLS_KEY_PROOF]
def test_domain_genesis_txns(bootstrap, domain_genesis_file): serializer = JsonSerializer() with open(domain_genesis_file) as f: i = 0 for line in store_utils.cleanLines(f.readlines()): txn = serializer.deserialize(line) assert get_seq_no(txn) assert get_payload_data(txn) assert get_type(txn) == NYM assert get_version(txn) == "1" assert get_payload_data(txn)[VERKEY] assert get_payload_data(txn)[TARGET_NYM] assert ALIAS not in get_payload_data(txn) # expect Trustees, then Stewards, then Clients if 0 <= i < TRUSTEE_COUNT: expected_role = TRUSTEE elif TRUSTEE_COUNT <= i < TRUSTEE_COUNT + NODE_COUNT: expected_role = STEWARD else: expected_role = None assert get_payload_data(txn).get(ROLE) == expected_role i += 1
def test_domain_genesis_txns(bootstrap, domain_genesis_file): serializer = JsonSerializer() with open(domain_genesis_file) as f: i = 0 for line in store_utils.cleanLines(f.readlines()): txn = serializer.deserialize(line) assert get_seq_no(txn) assert get_payload_data(txn) assert get_type(txn) == NYM assert get_version(txn) == "1" assert get_protocol_version(txn) is None assert get_payload_data(txn)[VERKEY] assert get_payload_data(txn)[TARGET_NYM] assert ALIAS not in get_payload_data(txn) # expect Trustees, then Stewards, then Clients if 0 <= i < TRUSTEE_COUNT: expected_role = TRUSTEE elif TRUSTEE_COUNT <= i < TRUSTEE_COUNT + NODE_COUNT: expected_role = STEWARD else: expected_role = None assert get_payload_data(txn).get(ROLE) == expected_role i += 1
def _lines(self): # Move to the beginning of file self.db_file.seek(0) return store_utils.cleanLines(self.db_file)
def _lines(self): # Move to the beginning of file self.db_file.seek(0) return store_utils.cleanLines(self.db_file)