cic-internal-integration/apps/cic-eth/cic_eth/runnable/daemons/filters/tx.py

51 lines
1.3 KiB
Python
Raw Normal View History

2021-02-17 09:19:42 +01:00
# standard imports
import logging
# third-party imports
import celery
2021-03-01 21:15:17 +01:00
from hexathon import (
add_0x,
)
2021-02-17 09:19:42 +01:00
# local imports
from cic_eth.db.models.otx import Otx
2021-03-01 21:15:17 +01:00
from chainsyncer.db.models.base import SessionBase
from chainlib.status import Status
2021-02-17 09:19:42 +01:00
from .base import SyncFilter
logg = logging.getLogger().getChild(__name__)
2021-02-17 09:19:42 +01:00
class TxFilter(SyncFilter):
2021-03-01 21:15:17 +01:00
def __init__(self, chain_spec, queue):
2021-02-17 09:19:42 +01:00
self.queue = queue
2021-03-01 21:15:17 +01:00
self.chain_spec = chain_spec
2021-02-17 09:19:42 +01:00
2021-03-01 21:15:17 +01:00
def filter(self, conn, block, tx, db_session=None):
db_session = SessionBase.bind_session(db_session)
tx_hash_hex = tx.hash
otx = Otx.load(add_0x(tx_hash_hex), session=db_session)
2021-02-17 09:19:42 +01:00
if otx == None:
logg.debug('tx {} not found locally, skipping'.format(tx_hash_hex))
return None
2021-03-06 18:55:51 +01:00
logg.info('tx filter match on {}'.format(otx.tx_hash))
db_session.flush()
2021-03-01 21:15:17 +01:00
SessionBase.release_session(db_session)
s = celery.signature(
2021-02-17 09:19:42 +01:00
'cic_eth.queue.tx.set_final_status',
[
2021-03-01 21:15:17 +01:00
add_0x(tx_hash_hex),
tx.block.number,
tx.status == Status.ERROR,
2021-02-17 09:19:42 +01:00
],
queue=self.queue,
)
t = s.apply_async()
return t
2021-03-01 21:15:17 +01:00
def __str__(self):
return 'cic-eth erc20 transfer filter'