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 testSerializeSubfields(): fields = OrderedDict([ ("f1.a", (str, str)), ("f1.b", (str, int)), ("f1.c", (str, float)), ("f2.d", (str, str)), ("f2.e", (str, int)), ("f2.f", (str, float)), ]) serializer = CompactSerializer(fields) json = { "f1": {"a": "v1", "b": 2, "c": 3.0}, "f2": {"d": "v1", "e": 3, "f": 4.0}, } assert b"v1|2|3.0|v1|3|4.0" == serializer.serialize(json)
def testSerializeSubfields(): fields = OrderedDict([ ("f1.a", (str, str)), ("f1.b", (str, int)), ("f1.c", (str, float)), ("f2.d", (str, str)), ("f2.e", (str, int)), ("f2.f", (str, float)), ]) serializer = CompactSerializer(fields) json = { "f1": { "a": "v1", "b": 2, "c": 3.0 }, "f2": { "d": "v1", "e": 3, "f": 4.0 }, } assert b"v1|2|3.0|v1|3|4.0" == serializer.serialize(json)