cic-stack/apps/cic-eth/cic_eth/runnable/daemons/filters/register.py

58 lines
1.6 KiB
Python
Raw Normal View History

2021-02-17 09:19:42 +01:00
# standard imports
import logging
# third-party imports
import celery
from chainlib.eth.address import to_checksum
2021-03-01 21:15:17 +01:00
from hexathon import (
add_0x,
strip_0x,
)
2021-02-17 09:19:42 +01:00
# local imports
from .base import SyncFilter
2021-03-01 21:15:17 +01:00
logg = logging.getLogger(__name__)
2021-02-17 09:19:42 +01:00
account_registry_add_log_hash = '0x5ed3bdd47b9af629827a8d129aa39c870b10c03f0153fe9ddb8e84b665061acd' # keccak256(AccountAdded(address,uint256))
class RegistrationFilter(SyncFilter):
2021-03-01 21:15:17 +01:00
def __init__(self, chain_spec, queue):
self.chain_spec = chain_spec
2021-02-21 16:41:37 +01:00
self.queue = queue
2021-03-01 21:15:17 +01:00
def filter(self, conn, block, tx, db_session=None):
2021-02-17 09:19:42 +01:00
registered_address = None
2021-03-01 21:15:17 +01:00
for l in tx.logs:
event_topic_hex = l['topics'][0]
2021-02-17 09:19:42 +01:00
if event_topic_hex == account_registry_add_log_hash:
2021-03-01 21:15:17 +01:00
# TODO: use abi conversion method instead
address_hex = strip_0x(l['topics'][1])[64-40:]
address = to_checksum(add_0x(address_hex))
2021-03-06 18:55:51 +01:00
logg.info('request token gift to {}'.format(address))
s_nonce = celery.signature(
'cic_eth.eth.tx.reserve_nonce',
2021-02-17 09:19:42 +01:00
[
address,
2021-03-06 18:55:51 +01:00
],
queue=self.queue,
)
s_gift = celery.signature(
'cic_eth.eth.account.gift',
[
2021-03-01 21:15:17 +01:00
str(self.chain_spec),
2021-02-17 09:19:42 +01:00
],
2021-02-21 16:41:37 +01:00
queue=self.queue,
2021-02-17 09:19:42 +01:00
)
2021-03-06 18:55:51 +01:00
s_nonce.link(s_gift)
s_nonce.apply_async()
2021-03-01 21:15:17 +01:00
def __str__(self):
return 'cic-eth account registration'