chaind-eth

Queue server for ethereum
Info | Log | Files | Refs | README | LICENSE

cache.py (1218B)


      1 # standard imports
      2 import logging
      3 
      4 # external imports
      5 from hexathon import strip_0x
      6 from chainqueue.cache import (
      7         CacheTx,
      8         NoopNormalizer,
      9         )
     10 from chainlib.eth.tx import unpack
     11 from chainlib.encode import TxHexNormalizer
     12 
     13 logg = logging.getLogger(__name__)
     14 
     15 class Normalizer(TxHexNormalizer, NoopNormalizer):
     16 
     17     def __init__(self):
     18         super(Normalizer, self).__init__()
     19         self.address = self.wallet_address
     20         self.hash = self.tx_hash
     21         #self.value = self.noop
     22 
     23 
     24     def value(self, v):
     25         hexathon.to_int(v)
     26 
     27 
     28 eth_normalizer = Normalizer()
     29 
     30 
     31 class EthCacheTx(CacheTx):
     32 
     33     def __init__(self, chain_spec):
     34         super(EthCacheTx, self).__init__(chain_spec)
     35 
     36 
     37     def deserialize(self, signed_tx):
     38         signed_tx_bytes = bytes.fromhex(strip_0x(signed_tx))
     39         tx = unpack(signed_tx_bytes, self.chain_spec)
     40         logg.debug('have tx {}'.format(tx))
     41         self.hash = eth_normalizer.hash(tx['hash'])
     42         self.sender = eth_normalizer.address(tx['from'])
     43         self.recipient = eth_normalizer.address(tx['to'])
     44         self.nonce = eth_normalizer.value(tx['nonce'])
     45         self.value = eth_normalizer.value(tx['value'])
     46         self.src = signed_tx