2021-02-17 09:19:42 +01:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# third-party imports
|
|
|
|
import celery
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
from cic_eth.db.models.otx import Otx
|
2021-02-19 08:06:05 +01:00
|
|
|
from cic_eth.db.models.base import SessionBase
|
2021-02-17 09:19:42 +01:00
|
|
|
from .base import SyncFilter
|
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
|
|
|
class TxFilter(SyncFilter):
|
|
|
|
|
|
|
|
def __init__(self, queue):
|
|
|
|
self.queue = queue
|
|
|
|
|
|
|
|
|
2021-02-19 08:06:05 +01:00
|
|
|
def filter(self, w3, tx, rcpt, chain_spec, session=None):
|
|
|
|
session = SessionBase.bind_session(session)
|
2021-02-17 09:19:42 +01:00
|
|
|
logg.debug('applying tx filter')
|
|
|
|
tx_hash_hex = tx.hash.hex()
|
2021-02-19 08:06:05 +01:00
|
|
|
otx = Otx.load(tx_hash_hex, session=session)
|
|
|
|
SessionBase.release_session(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
|
|
|
|
logg.info('otx found {}'.format(otx.tx_hash))
|
2021-02-19 08:06:05 +01:00
|
|
|
s = celery.signature(
|
2021-02-17 09:19:42 +01:00
|
|
|
'cic_eth.queue.tx.set_final_status',
|
|
|
|
[
|
|
|
|
tx_hash_hex,
|
|
|
|
rcpt.blockNumber,
|
|
|
|
rcpt.status == 0,
|
|
|
|
],
|
|
|
|
queue=self.queue,
|
|
|
|
)
|
|
|
|
t = s.apply_async()
|
|
|
|
return t
|