chainqueue

Blockchain transaction queue control
Log | Files | Refs | LICENSE

commit ed75502f46285bec406388f7939064814f713423
parent 68f50246d2c729428b477fda07b29f50df9370d6
Author: lash <dev@holbrook.no>
Date:   Sat, 12 Mar 2022 12:02:45 +0000

Add network token value to core cache tx object

Diffstat:
Mchainqueue/cache.py | 22++++++++++++----------
Mtests/test_cache.py | 22+++++++++++++++++++++-
2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/chainqueue/cache.py b/chainqueue/cache.py @@ -5,11 +5,12 @@ import enum class CacheTx: def __init__(self): - self.v_sender = None - self.v_recipient = None - self.v_nonce = None - self.v_value = None + self.sender = None + self.recipient = None + self.nonce = None + self.value = None + self.tx_hash = None self.block_number = None self.tx_index = None self.timestamp = None @@ -21,11 +22,12 @@ class CacheTx: self.timestamp = timestamp - def init(self, nonce, sender, recipient, value): - self.v_sender = sender - self.v_recipient = recipient - self.v_nonce = nonce - self.v_value = value + def init(self, tx_hash, nonce, sender, recipient, value): + self.tx_hash = tx_hash + self.sender = sender + self.recipient = recipient + self.nonce = nonce + self.value = value def deserialize(self, signed_tx): @@ -38,7 +40,7 @@ class CacheTx: def __str__(self): - return '{} -> {} : {}'.format(self.v_sender, self.v_recipient, self.v_value) + return '{}: {} ({}) -> {} = {}'.format(self.tx_hash, self.sender, self.nonce, self.recipient, self.value) diff --git a/tests/test_cache.py b/tests/test_cache.py @@ -11,6 +11,7 @@ from hexathon import add_0x from chainqueue import QueueEntry from chainqueue.cache import ( CacheTokenTx, + Cache, ) # test imports @@ -45,16 +46,35 @@ class MockCacheTokenTx(CacheTokenTx): z = h.digest() token = z.hex() + h = hashlib.sha256() + h.update(z) + z = h.digest() + tx_hash = z.hex() + tx = CacheTokenTx() - tx.init(nonce, sender, recipient, value) + tx.init(tx_hash, nonce, sender, recipient, value) tx.set('src_token', token) tx.set('dst_token', token) tx.set('src_value', token_value) tx.set('dst_value', token_value) + tx.confirm(42, 13, 1024000) return tx +class MockTokenCache(Cache): + + def __init__(self): + self.db = {} + + def put(self, chain_spec, cache_tx): + self.db[cache_tx.tx_hash] = cache_tx + + + def get(self, chain_spec, tx_hash): + pass + + class TestCache(TestShepBase): def setUp(self):