chainqueue

Blockchain transaction queue control
Log | Files | Refs | LICENSE

commit c094ca21982ce17319b06cfcc1a2b5fd56978a16
parent e4cc7061f0dc7c0a90bd0c0adbf8ed2896e35410
Author: lash <dev@holbrook.no>
Date:   Tue, 15 Mar 2022 09:00:15 +0000

Implement chainspec in entry, cache tx

Diffstat:
Mchainqueue/cache/base.py | 9+++++----
Mchainqueue/store/base.py | 2+-
Mtests/test_cache.py | 4++--
3 files changed, 8 insertions(+), 7 deletions(-)

diff --git 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 @@ -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 @@ -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)