Revert session changes
This commit is contained in:
parent
9c687db9c0
commit
107ae0b88e
@ -52,12 +52,10 @@ def create(nonce, holder_address, tx_hash, signed_tx, chain_str, obsolete_predec
|
||||
:returns: transaction hash
|
||||
:rtype: str, 0x-hash
|
||||
"""
|
||||
#session = SessionBase.create_session()
|
||||
#sqlalchemy.exc.TimeoutError
|
||||
session = SessionBase.bind_session()
|
||||
session = SessionBase.create_session()
|
||||
lock = Lock.check_aggregate(chain_str, LockEnum.QUEUE, holder_address, session=session)
|
||||
if lock > 0:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise LockedError(lock)
|
||||
|
||||
o = Otx.add(
|
||||
@ -83,9 +81,7 @@ def create(nonce, holder_address, tx_hash, signed_tx, chain_str, obsolete_predec
|
||||
otx.cancel(confirmed=False, session=session)
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
logg.debug('queue created nonce {} from {} hash {}'.format(nonce, holder_address, tx_hash))
|
||||
return tx_hash
|
||||
|
||||
@ -103,8 +99,7 @@ def set_sent_status(tx_hash, fail=False):
|
||||
:returns: True if tx is known, False otherwise
|
||||
:rtype: boolean
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
o = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if o == None:
|
||||
logg.warning('not local tx, skipping {}'.format(tx_hash))
|
||||
@ -117,8 +112,7 @@ def set_sent_status(tx_hash, fail=False):
|
||||
o.sent(session=session)
|
||||
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -135,8 +129,7 @@ def set_final_status(tx_hash, block=None, fail=False):
|
||||
:type fail: boolean
|
||||
:raises NotLocalTxError: If transaction not found in queue.
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(
|
||||
Otx.nonce.label('nonce'),
|
||||
TxCache.sender.label('sender'),
|
||||
@ -147,7 +140,7 @@ def set_final_status(tx_hash, block=None, fail=False):
|
||||
o = q.first()
|
||||
|
||||
if o == None:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
session.flush()
|
||||
@ -175,8 +168,7 @@ def set_final_status(tx_hash, block=None, fail=False):
|
||||
otwo.cancel(True, session=session)
|
||||
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -195,10 +187,9 @@ def set_cancel(tx_hash, manual=False):
|
||||
"""
|
||||
|
||||
session = SessionBase.create_session()
|
||||
|
||||
o = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if o == None:
|
||||
session.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
session.flush()
|
||||
@ -209,8 +200,7 @@ def set_cancel(tx_hash, manual=False):
|
||||
o.cancel(session=session)
|
||||
|
||||
session.commit()
|
||||
|
||||
session.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -226,19 +216,17 @@ def set_rejected(tx_hash):
|
||||
:raises NotLocalTxError: If transaction not found in queue.
|
||||
"""
|
||||
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
o = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if o == None:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
session.flush()
|
||||
|
||||
o.reject(session=session)
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -254,19 +242,17 @@ def set_fubar(tx_hash):
|
||||
:raises NotLocalTxError: If transaction not found in queue.
|
||||
"""
|
||||
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
o = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if o == None:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
session.flush()
|
||||
|
||||
o.fubar(session=session)
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -282,19 +268,17 @@ def set_manual(tx_hash):
|
||||
:raises NotLocalTxError: If transaction not found in queue.
|
||||
"""
|
||||
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
o = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if o == None:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
session.flush()
|
||||
|
||||
o.manual(session=session)
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -307,13 +291,11 @@ def set_ready(tx_hash):
|
||||
:type tx_hash: str, 0x-hex
|
||||
:raises NotLocalTxError: If transaction not found in queue.
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
o = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if o == None:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
session.flush()
|
||||
|
||||
if o.status & StatusBits.GAS_ISSUES or o.status == StatusEnum.PENDING:
|
||||
@ -322,8 +304,7 @@ def set_ready(tx_hash):
|
||||
o.retry(session=session)
|
||||
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -338,19 +319,18 @@ def set_waitforgas(tx_hash):
|
||||
:type tx_hash: str, 0x-hex
|
||||
:raises NotLocalTxError: If transaction not found in queue.
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
o = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if o == None:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
session.flush()
|
||||
|
||||
o.waitforgas(session=session)
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return tx_hash
|
||||
|
||||
@ -360,17 +340,16 @@ def get_state_log(tx_hash):
|
||||
|
||||
logs = []
|
||||
|
||||
session = SessionBase.bind_session()
|
||||
session = SessionBase.create_session()
|
||||
|
||||
q = session.query(OtxStateLog)
|
||||
q = q.join(Otx)
|
||||
q = q.filter(Otx.tx_hash==tx_hash)
|
||||
q = q.order_by(OtxStateLog.date.asc())
|
||||
|
||||
for l in q.all():
|
||||
logs.append((l.date, l.status,))
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return logs
|
||||
|
||||
@ -385,14 +364,13 @@ def get_tx_cache(tx_hash):
|
||||
:returns: Transaction data
|
||||
:rtype: dict
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Otx)
|
||||
q = q.filter(Otx.tx_hash==tx_hash)
|
||||
otx = q.first()
|
||||
|
||||
if otx == None:
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
raise NotLocalTxError(tx_hash)
|
||||
|
||||
session.flush()
|
||||
@ -401,7 +379,7 @@ def get_tx_cache(tx_hash):
|
||||
q = q.filter(TxCache.otx_id==otx.id)
|
||||
txc = q.first()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
tx = {
|
||||
'tx_hash': otx.tx_hash,
|
||||
@ -436,8 +414,7 @@ def get_lock(address=None):
|
||||
:returns: List of locks
|
||||
:rtype: list of dicts
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(
|
||||
Lock.date_created,
|
||||
Lock.address,
|
||||
@ -459,8 +436,7 @@ def get_lock(address=None):
|
||||
'flags': lock[2],
|
||||
}
|
||||
locks.append(o)
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return locks
|
||||
|
||||
@ -475,14 +451,8 @@ def get_tx(tx_hash):
|
||||
:returns: nonce, address and signed_tx (raw signed transaction)
|
||||
:rtype: dict
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
q = session.query(Otx)
|
||||
q = q.filter(Otx.tx_hash==tx_hash)
|
||||
tx = q.first()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
|
||||
session = SessionBase.create_session()
|
||||
tx = session.query(Otx).filter(Otx.tx_hash==tx_hash).first()
|
||||
if tx == None:
|
||||
raise NotLocalTxError('queue does not contain tx hash {}'.format(tx_hash))
|
||||
|
||||
@ -493,7 +463,7 @@ def get_tx(tx_hash):
|
||||
'status': tx.status,
|
||||
}
|
||||
logg.debug('get tx {}'.format(o))
|
||||
|
||||
session.close()
|
||||
return o
|
||||
|
||||
|
||||
@ -508,8 +478,7 @@ def get_nonce_tx(nonce, sender, chain_id):
|
||||
:returns: Transactions
|
||||
:rtype: dict, with transaction hash as key, signed raw transaction as value
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Otx)
|
||||
q = q.join(TxCache)
|
||||
q = q.filter(TxCache.sender==sender)
|
||||
@ -522,7 +491,7 @@ def get_nonce_tx(nonce, sender, chain_id):
|
||||
if sender == None or tx['from'] == sender:
|
||||
txs[r.tx_hash] = r.signed_tx
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return txs
|
||||
|
||||
@ -542,14 +511,12 @@ def get_paused_txs(status=None, sender=None, chain_id=0):
|
||||
:returns: Transactions
|
||||
:rtype: dict, with transaction hash as key, signed raw transaction as value
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Otx)
|
||||
|
||||
if status != None:
|
||||
#if status == StatusEnum.PENDING or status >= StatusEnum.SENT:
|
||||
if status == StatusEnum.PENDING or status & StatusBits.IN_NETWORK or not is_alive(status):
|
||||
SessionBase.release_session(session)
|
||||
raise ValueError('not a valid paused tx value: {}'.format(status))
|
||||
q = q.filter(Otx.status.op('&')(status.value)==status.value)
|
||||
q = q.join(TxCache)
|
||||
@ -569,7 +536,7 @@ def get_paused_txs(status=None, sender=None, chain_id=0):
|
||||
#gas += tx['gas'] * tx['gasPrice']
|
||||
txs[r.tx_hash] = r.signed_tx
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return txs
|
||||
|
||||
@ -587,9 +554,7 @@ def get_status_tx(status, before=None, exact=False, limit=0):
|
||||
:rtype: list of cic_eth.db.models.otx.Otx
|
||||
"""
|
||||
txs = {}
|
||||
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Otx)
|
||||
q = q.join(TxCache)
|
||||
q = q.filter(TxCache.date_updated<before)
|
||||
@ -603,9 +568,7 @@ def get_status_tx(status, before=None, exact=False, limit=0):
|
||||
break
|
||||
txs[o.tx_hash] = o.signed_tx
|
||||
i += 1
|
||||
|
||||
SessionBase.release_session(session)
|
||||
|
||||
session.close()
|
||||
return txs
|
||||
|
||||
|
||||
@ -629,8 +592,7 @@ def get_upcoming_tx(status=StatusEnum.READYSEND, recipient=None, before=None, ch
|
||||
:returns: Transactions
|
||||
:rtype: dict, with transaction hash as key, signed raw transaction as value
|
||||
"""
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q_outer = session.query(
|
||||
TxCache.sender,
|
||||
func.min(Otx.nonce).label('nonce'),
|
||||
@ -640,7 +602,6 @@ def get_upcoming_tx(status=StatusEnum.READYSEND, recipient=None, before=None, ch
|
||||
q_outer = q_outer.filter(or_(Lock.flags==None, Lock.flags.op('&')(LockEnum.SEND.value)==0))
|
||||
|
||||
if not is_alive(status):
|
||||
SessionBase.release_session(session)
|
||||
raise ValueError('not a valid non-final tx value: {}'.format(status))
|
||||
if status == StatusEnum.PENDING:
|
||||
q_outer = q_outer.filter(Otx.status==status.value)
|
||||
@ -682,7 +643,7 @@ def get_upcoming_tx(status=StatusEnum.READYSEND, recipient=None, before=None, ch
|
||||
session.add(o)
|
||||
session.commit()
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return txs
|
||||
|
||||
@ -708,8 +669,7 @@ def get_account_tx(address, as_sender=True, as_recipient=True, counterpart=None)
|
||||
|
||||
txs = {}
|
||||
|
||||
session = SessionBase.bind_session()
|
||||
|
||||
session = SessionBase.create_session()
|
||||
q = session.query(Otx)
|
||||
q = q.join(TxCache)
|
||||
if as_sender and as_recipient:
|
||||
@ -726,8 +686,7 @@ def get_account_tx(address, as_sender=True, as_recipient=True, counterpart=None)
|
||||
logg.debug('tx {} already recorded'.format(r.tx_hash))
|
||||
continue
|
||||
txs[r.tx_hash] = r.signed_tx
|
||||
|
||||
SessionBase.release_session(session)
|
||||
session.close()
|
||||
|
||||
return txs
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user