Add network token value to core cache tx object

This commit is contained in:
lash 2022-03-12 12:02:45 +00:00
parent 68f50246d2
commit ed75502f46
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 33 additions and 11 deletions

View File

@ -5,11 +5,12 @@ import enum
class CacheTx: class CacheTx:
def __init__(self): def __init__(self):
self.v_sender = None self.sender = None
self.v_recipient = None self.recipient = None
self.v_nonce = None self.nonce = None
self.v_value = None self.value = None
self.tx_hash = None
self.block_number = None self.block_number = None
self.tx_index = None self.tx_index = None
self.timestamp = None self.timestamp = None
@ -21,11 +22,12 @@ class CacheTx:
self.timestamp = timestamp self.timestamp = timestamp
def init(self, nonce, sender, recipient, value): def init(self, tx_hash, nonce, sender, recipient, value):
self.v_sender = sender self.tx_hash = tx_hash
self.v_recipient = recipient self.sender = sender
self.v_nonce = nonce self.recipient = recipient
self.v_value = value self.nonce = nonce
self.value = value
def deserialize(self, signed_tx): def deserialize(self, signed_tx):
@ -38,7 +40,7 @@ class CacheTx:
def __str__(self): 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)

View File

@ -11,6 +11,7 @@ from hexathon import add_0x
from chainqueue import QueueEntry from chainqueue import QueueEntry
from chainqueue.cache import ( from chainqueue.cache import (
CacheTokenTx, CacheTokenTx,
Cache,
) )
# test imports # test imports
@ -45,16 +46,35 @@ class MockCacheTokenTx(CacheTokenTx):
z = h.digest() z = h.digest()
token = z.hex() token = z.hex()
h = hashlib.sha256()
h.update(z)
z = h.digest()
tx_hash = z.hex()
tx = CacheTokenTx() tx = CacheTokenTx()
tx.init(nonce, sender, recipient, value) tx.init(tx_hash, nonce, sender, recipient, value)
tx.set('src_token', token) tx.set('src_token', token)
tx.set('dst_token', token) tx.set('dst_token', token)
tx.set('src_value', token_value) tx.set('src_value', token_value)
tx.set('dst_value', token_value) tx.set('dst_value', token_value)
tx.confirm(42, 13, 1024000)
return tx 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): class TestCache(TestShepBase):
def setUp(self): def setUp(self):