diff --git a/chainqueue/cache/base.py b/chainqueue/cache/base.py index d5a7813..d94fe0f 100644 --- a/chainqueue/cache/base.py +++ b/chainqueue/cache/base.py @@ -16,13 +16,12 @@ class NoopNormalizer: def noop(self, v): return v - noop_normalizer = NoopNormalizer() class CacheTx: - def __init__(self, normalizer=noop_normalizer): + def __init__(self, chain_spec, normalizer=noop_normalizer): self.normalizer = normalizer self.sender = None self.recipient = None @@ -34,6 +33,8 @@ class CacheTx: self.tx_index = None self.timestamp = None + self.chain_spec = chain_spec + def confirm(self, block_number, tx_index, timestamp): self.block_number = block_number @@ -65,8 +66,8 @@ class CacheTx: class CacheTokenTx(CacheTx): - def __init__(self, normalizer=noop_normalizer): - super(CacheTokenTx, self).__init__(normalizer=normalizer) + def __init__(self, chain_spec, normalizer=noop_normalizer): + super(CacheTokenTx, self).__init__(chain_spec, normalizer=normalizer) self.v_src_token = None self.v_src_value = None self.v_dst_token = None diff --git a/chainqueue/store/base.py b/chainqueue/store/base.py index 3880605..f281351 100644 --- a/chainqueue/store/base.py +++ b/chainqueue/store/base.py @@ -42,7 +42,7 @@ class Store: def put(self, v, cache_adapter=CacheTx): - tx = cache_adapter() + tx = cache_adapter(self.chain_spec) tx.deserialize(v) k = tx.hash n = self.counter.next() diff --git a/tests/test_cache.py b/tests/test_cache.py index 4c7217a..78bff99 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -52,7 +52,7 @@ class TestCache(TestShepBase): def test_cache_instance(self): normalizer = MockNormalizer() a = b'foo' - tx = MockCacheTokenTx(normalizer=normalizer) + tx = MockCacheTokenTx(self.chain_spec, normalizer=normalizer) tx.deserialize(a) self.assertTrue(isinstance(tx.value, float)) self.assertEqual(tx.sender[:4], 'addr') @@ -62,7 +62,7 @@ class TestCache(TestShepBase): def test_cache_putget(self): a = b'foo' - tx = MockCacheTokenTx() + tx = MockCacheTokenTx(self.chain_spec) tx.deserialize(a) self.cache.put(self.chain_spec, tx) tx_retrieved = self.cache.get(self.chain_spec, tx.hash)