cic-internal-integration/apps/cic-eth/cic_eth/queue/time.py

51 lines
1.3 KiB
Python
Raw Permalink Normal View History

# standard imports
import logging
# third-party imports
import celery
from chainlib.chain import ChainSpec
from chainlib.connection import RPCConnection
from chainlib.eth.block import block_by_hash
from chainlib.eth.tx import receipt
2021-04-04 14:40:59 +02:00
from chainqueue.db.models.otx import Otx
from chainqueue.error import NotLocalTxError
# local imports
2021-03-01 21:15:17 +01:00
from cic_eth.task import CriticalSQLAlchemyAndWeb3Task
2021-04-25 16:54:54 +02:00
from cic_eth.db.models.base import SessionBase
2021-08-28 13:10:18 +02:00
from cic_eth.encode import tx_normalize
celery_app = celery.current_app
logg = logging.getLogger()
2021-04-04 14:40:59 +02:00
def tx_times(tx_hash, chain_spec, session=None):
2021-08-28 13:10:18 +02:00
tx_hash = tx_normalize.tx_hash(tx_hash)
2021-04-04 14:40:59 +02:00
session = SessionBase.bind_session(session)
rpc = RPCConnection.connect(chain_spec, 'default')
time_pair = {
'network': None,
'queue': None,
}
try:
o = receipt(tx_hash)
r = rpc.do(o)
o = block_by_hash(r['block_hash'])
block = rpc.do(o)
logg.debug('rcpt {}'.format(block))
time_pair['network'] = block['timestamp']
except Exception as e:
logg.debug('error with getting timestamp details for {}: {}'.format(tx_hash, e))
pass
2021-04-04 14:40:59 +02:00
otx = Otx.load(tx_hash, session=session)
if otx != None:
time_pair['queue'] = int(otx['date_created'].timestamp())
2021-04-04 14:40:59 +02:00
SessionBase.release_session(session)
return time_pair