2021-02-17 09:19:42 +01:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# third-party imports
|
|
|
|
import celery
|
2021-03-29 15:27:53 +02:00
|
|
|
from chainlib.eth.address import to_checksum_address
|
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-29 15:27:53 +02:00
|
|
|
logg = logging.getLogger().getChild(__name__)
|
2021-02-17 09:19:42 +01:00
|
|
|
|
2021-03-29 15:27:53 +02:00
|
|
|
account_registry_add_log_hash = '0x5ed3bdd47b9af629827a8d129aa39c870b10c03f0153fe9ddb8e84b665061acd'
|
2021-02-17 09:19:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
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:]
|
2021-03-29 15:27:53 +02:00
|
|
|
address = to_checksum_address(add_0x(address_hex))
|
2021-03-06 18:55:51 +01:00
|
|
|
logg.info('request token gift to {}'.format(address))
|
|
|
|
s_nonce = celery.signature(
|
2021-04-04 14:40:59 +02:00
|
|
|
'cic_eth.eth.nonce.reserve_nonce',
|
2021-02-17 09:19:42 +01:00
|
|
|
[
|
|
|
|
address,
|
2021-04-04 14:40:59 +02:00
|
|
|
self.chain_spec.asdict(),
|
2021-03-06 18:55:51 +01:00
|
|
|
],
|
|
|
|
queue=self.queue,
|
|
|
|
)
|
|
|
|
s_gift = celery.signature(
|
|
|
|
'cic_eth.eth.account.gift',
|
|
|
|
[
|
2021-03-29 15:27:53 +02:00
|
|
|
self.chain_spec.asdict(),
|
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'
|
|
|
|
|