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

48 lines
1.2 KiB
Python
Raw 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
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):
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