Correct reverse lookup method registry for tx collate

This commit is contained in:
nolash 2021-07-14 16:02:56 +02:00
parent d78ca4da2c
commit b6f1a31d87
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 10 additions and 8 deletions

View File

@ -14,6 +14,7 @@ from chainlib.eth.tx import (
) )
from chainlib.eth.block import block_by_number from chainlib.eth.block import block_by_number
from chainlib.eth.contract import abi_decode_single from chainlib.eth.contract import abi_decode_single
from chainlib.eth.constant import ZERO_ADDRESS
from hexathon import strip_0x from hexathon import strip_0x
from cic_eth_registry import CICRegistry from cic_eth_registry import CICRegistry
from cic_eth_registry.erc20 import ERC20Token from cic_eth_registry.erc20 import ERC20Token
@ -138,8 +139,8 @@ def list_tx_by_bloom(self, bloomspec, address, chain_spec_dict):
# TODO: Surely it must be possible to optimize this # TODO: Surely it must be possible to optimize this
# TODO: DRY this with callback filter in cic_eth/runnable/manager # TODO: DRY this with callback filter in cic_eth/runnable/manager
# TODO: Remove redundant fields from end representation (timestamp, tx_hash) # TODO: Remove redundant fields from end representation (timestamp, tx_hash)
@celery_app.task() @celery_app.task(bind=True, base=BaseTask)
def tx_collate(tx_batches, chain_spec_dict, offset, limit, newest_first=True, verify_contracts=True): def tx_collate(self, tx_batches, chain_spec_dict, offset, limit, newest_first=True, verify_contracts=True):
"""Merges transaction data from multiple sources and sorts them in chronological order. """Merges transaction data from multiple sources and sorts them in chronological order.
:param tx_batches: Transaction data inputs :param tx_batches: Transaction data inputs
@ -191,7 +192,7 @@ def tx_collate(tx_batches, chain_spec_dict, offset, limit, newest_first=True, ve
tx = txs_by_block[k] tx = txs_by_block[k]
if verify_contracts: if verify_contracts:
try: try:
tx = verify_and_expand(tx, chain_spec) tx = verify_and_expand(tx, chain_spec, sender_address=BaseTask.call_address)
except UnknownContractError: except UnknownContractError:
logg.error('verify failed on tx {}, skipping'.format(tx['hash'])) logg.error('verify failed on tx {}, skipping'.format(tx['hash']))
continue continue
@ -200,18 +201,18 @@ def tx_collate(tx_batches, chain_spec_dict, offset, limit, newest_first=True, ve
return txs return txs
def verify_and_expand(tx, chain_spec): def verify_and_expand(tx, chain_spec, sender_address=ZERO_ADDRESS):
rpc = RPCConnection.connect(chain_spec, 'default') rpc = RPCConnection.connect(chain_spec, 'default')
registry = CICRegistry(chain_spec, rpc) registry = CICRegistry(chain_spec, rpc)
if tx.get('source_token_symbol') == None: if tx.get('source_token_symbol') == None and tx['source_token'] != ZERO_ADDRESS:
registry.lookup_reverse(tx['source_token']) r = registry.by_address(tx['source_token'], sender_address=sender_address)
token = ERC20Token(chain_spec, rpc, tx['source_token']) token = ERC20Token(chain_spec, rpc, tx['source_token'])
tx['source_token_symbol'] = token.symbol tx['source_token_symbol'] = token.symbol
tx['source_token_decimals'] = token.decimals tx['source_token_decimals'] = token.decimals
if tx.get('destination_token_symbol') == None: if tx.get('destination_token_symbol') == None and tx['destination_token'] != ZERO_ADDRESS:
registry.lookup_reverse(tx['destination_token']) r = registry.by_address(tx['destination_token'], sender_address=sender_address)
token = ERC20Token(chain_spec, rpc, tx['destination_token']) token = ERC20Token(chain_spec, rpc, tx['destination_token'])
tx['destination_token_symbol'] = token.symbol tx['destination_token_symbol'] = token.symbol
tx['destination_token_decimals'] = token.decimals tx['destination_token_decimals'] = token.decimals

View File

@ -32,6 +32,7 @@ def test_ext_tx_collate(
register_tokens, register_tokens,
cic_registry, cic_registry,
register_lookups, register_lookups,
init_celery_tasks,
celery_session_worker, celery_session_worker,
): ):