2021-02-17 10:33:18 +01:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# third-party imports
|
|
|
|
import celery
|
2021-03-29 15:27:53 +02:00
|
|
|
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-02 18:45:51 +02:00
|
|
|
from chainqueue.db.models.otx import Otx
|
|
|
|
from chainqueue.error import NotLocalTxError
|
2021-02-17 10:33:18 +01:00
|
|
|
|
|
|
|
# local imports
|
2021-03-01 21:15:17 +01:00
|
|
|
from cic_eth.task import CriticalSQLAlchemyAndWeb3Task
|
2021-02-17 10:33:18 +01:00
|
|
|
|
|
|
|
celery_app = celery.current_app
|
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
2021-04-02 23:26:13 +02:00
|
|
|
def tx_times(tx_hash, chain_spec, session=None):
|
|
|
|
|
|
|
|
session = SessionBase.bind_session(session)
|
|
|
|
|
2021-03-29 15:27:53 +02:00
|
|
|
rpc = RPCConnection.connect(chain_spec, 'default')
|
2021-02-17 10:33:18 +01:00
|
|
|
time_pair = {
|
|
|
|
'network': None,
|
|
|
|
'queue': None,
|
|
|
|
}
|
|
|
|
try:
|
2021-03-29 15:27:53 +02:00
|
|
|
o = receipt(tx_hash)
|
|
|
|
r = rpc.do(o)
|
|
|
|
o = block_by_hash(r['block_hash'])
|
|
|
|
block = rpc.do(o)
|
2021-02-17 10:33:18 +01:00
|
|
|
logg.debug('rcpt {}'.format(block))
|
|
|
|
time_pair['network'] = block['timestamp']
|
2021-03-29 15:27:53 +02:00
|
|
|
except Exception as e:
|
|
|
|
logg.debug('error with getting timestamp details for {}: {}'.format(tx_hash, e))
|
2021-02-17 10:33:18 +01:00
|
|
|
pass
|
|
|
|
|
2021-04-02 23:26:13 +02:00
|
|
|
otx = Otx.load(tx_hash, session=session)
|
2021-02-17 10:33:18 +01:00
|
|
|
if otx != None:
|
|
|
|
time_pair['queue'] = int(otx['date_created'].timestamp())
|
|
|
|
|
2021-04-02 23:26:13 +02:00
|
|
|
SessionBase.release_session(session)
|
|
|
|
|
2021-02-17 10:33:18 +01:00
|
|
|
return time_pair
|