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-10-07 17:12:35 +02:00
|
|
|
#logg = logging.getLogger(__name__)
|
|
|
|
logg = logging.getLogger()
|
2021-02-17 09:19:42 +01:00
|
|
|
|
2021-05-05 18:25:21 +02:00
|
|
|
account_registry_add_log_hash = '0x9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c9430'
|
2021-02-17 09:19:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RegistrationFilter(SyncFilter):
|
|
|
|
|
2021-07-12 21:50:32 +02:00
|
|
|
def __init__(self, chain_spec, contract_address, queue=None):
|
2021-03-01 21:15:17 +01:00
|
|
|
self.chain_spec = chain_spec
|
2021-02-21 16:41:37 +01:00
|
|
|
self.queue = queue
|
2021-07-12 21:50:32 +02:00
|
|
|
self.contract_address = contract_address
|
2021-02-21 16:41:37 +01:00
|
|
|
|
|
|
|
|
2021-03-01 21:15:17 +01:00
|
|
|
def filter(self, conn, block, tx, db_session=None):
|
2021-07-12 21:50:32 +02:00
|
|
|
if self.contract_address != tx.inputs[0]:
|
|
|
|
logg.debug('not an account registry tx; {} != {}'.format(self.contract_address, tx.inputs[0]))
|
|
|
|
return 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)
|
2021-05-31 17:34:16 +02:00
|
|
|
t = s_nonce.apply_async()
|
|
|
|
return t
|
2021-03-01 21:15:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'cic-eth account registration'
|
|
|
|
|