Account register test passes
This commit is contained in:
@@ -3,13 +3,14 @@ import logging
|
||||
import time
|
||||
import datetime
|
||||
|
||||
# third-party imports
|
||||
# external imports
|
||||
import celery
|
||||
from hexathon import strip_0x
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy import not_
|
||||
from sqlalchemy import tuple_
|
||||
from sqlalchemy import func
|
||||
from chainlib.eth.tx import unpack
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.otx import Otx
|
||||
@@ -95,6 +96,50 @@ def create(nonce, holder_address, tx_hash, signed_tx, chain_spec, obsolete_prede
|
||||
return tx_hash
|
||||
|
||||
|
||||
def register_tx(tx_hash_hex, tx_signed_raw_hex, chain_spec, queue, cache_task=None, session=None):
|
||||
"""Signs the provided transaction, and adds it to the transaction queue cache (with status PENDING).
|
||||
|
||||
:param tx: Standard ethereum transaction data
|
||||
:type tx: dict
|
||||
:param chain_spec: Chain spec of transaction to add to queue
|
||||
:type chain_spec: chainlib.chain.ChainSpec
|
||||
:param queue: Task queue
|
||||
:type queue: str
|
||||
:param cache_task: Cache task to call with signed transaction. If None, no task will be called.
|
||||
:type cache_task: str
|
||||
:raises: sqlalchemy.exc.DatabaseError
|
||||
:returns: Tuple; Transaction hash, signed raw transaction data
|
||||
:rtype: tuple
|
||||
"""
|
||||
logg.debug('adding queue tx {}:{} -> {}'.format(chain_spec, tx_hash_hex, tx_signed_raw_hex))
|
||||
tx_signed_raw = bytes.fromhex(strip_0x(tx_signed_raw_hex))
|
||||
tx = unpack(tx_signed_raw, chain_id=chain_spec.chain_id())
|
||||
|
||||
create(
|
||||
tx['nonce'],
|
||||
tx['from'],
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
chain_spec,
|
||||
session=session,
|
||||
)
|
||||
|
||||
if cache_task != None:
|
||||
logg.debug('adding cache task {} tx {}'.format(cache_task, tx_hash_hex))
|
||||
s_cache = celery.signature(
|
||||
cache_task,
|
||||
[
|
||||
tx_hash_hex,
|
||||
tx_signed_raw_hex,
|
||||
chain_spec.asdict(),
|
||||
],
|
||||
queue=queue,
|
||||
)
|
||||
s_cache.apply_async()
|
||||
|
||||
return (tx_hash_hex, tx_signed_raw_hex,)
|
||||
|
||||
|
||||
# TODO: Replace set_* with single task for set status
|
||||
@celery_app.task(base=CriticalSQLAlchemyTask)
|
||||
def set_sent_status(tx_hash, fail=False):
|
||||
|
||||
Reference in New Issue
Block a user