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(new_domain_genesis): os.remove(new_domain_genesis) if os.path.exists(new_pool_genesis): os.remove(new_pool_genesis) if os.path.exists(old_domain_genesis): old_ser = CompactSerializer(getTxnOrderedFields()) new_ser = JsonSerializer() with open(old_domain_genesis, 'r') as f1: with open(new_domain_genesis, 'w') as f2: for line in store_utils.cleanLines(f1): txn = old_ser.deserialize(line) txn = {k: v for k, v in txn.items() if v} txn = new_ser.serialize(txn, toBytes=False) f2.write(txn) f2.write('\n') os.remove(old_domain_genesis) if os.path.exists(old_pool_genesis): os.rename(old_pool_genesis, new_pool_genesis)
def testDeserializeSubfields(): 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 json == serializer.deserialize(b"v1|2|3.0|v1|3|4.0")
def testDeserializeSubfields(): 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 json == serializer.deserialize(b"v1|2|3.0|v1|3|4.0")