Implement chainspec in entry, cache tx

This commit is contained in:
lash 2022-03-15 09:00:15 +00:00
parent e4cc7061f0
commit c094ca2198
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 8 additions and 7 deletions

View File

@ -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

View File

@ -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()

View File

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