Only match account registry on correct contract address
This commit is contained in:
parent
c52885a016
commit
54dd5acb62
@ -12,20 +12,24 @@ from hexathon import (
|
||||
# local imports
|
||||
from .base import SyncFilter
|
||||
|
||||
logg = logging.getLogger().getChild(__name__)
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
account_registry_add_log_hash = '0x9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c9430'
|
||||
|
||||
|
||||
class RegistrationFilter(SyncFilter):
|
||||
|
||||
def __init__(self, chain_spec, queue):
|
||||
def __init__(self, chain_spec, contract_address, queue=None):
|
||||
self.chain_spec = chain_spec
|
||||
self.queue = queue
|
||||
self.contract_address = contract_address
|
||||
|
||||
|
||||
def filter(self, conn, block, tx, db_session=None):
|
||||
registered_address = None
|
||||
if self.contract_address != tx.inputs[0]:
|
||||
logg.debug('not an account registry tx; {} != {}'.format(self.contract_address, tx.inputs[0]))
|
||||
return None
|
||||
|
||||
for l in tx.logs:
|
||||
event_topic_hex = l['topics'][0]
|
||||
if event_topic_hex == account_registry_add_log_hash:
|
||||
|
@ -78,6 +78,14 @@ chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
|
||||
|
||||
cic_base.rpc.setup(chain_spec, config.get('ETH_PROVIDER'))
|
||||
|
||||
rpc = RPCConnection.connect(chain_spec, 'default')
|
||||
registry = None
|
||||
try:
|
||||
registry = connect_registry(rpc, chain_spec, config.get('CIC_REGISTRY_ADDRESS'))
|
||||
except UnknownContractError as e:
|
||||
logg.exception('Registry contract connection failed for {}: {}'.format(config.get('CIC_REGISTRY_ADDRESS'), e))
|
||||
sys.exit(1)
|
||||
logg.info('connected contract registry {}'.format(config.get('CIC_REGISTRY_ADDRESS')))
|
||||
|
||||
|
||||
def main():
|
||||
@ -85,7 +93,6 @@ def main():
|
||||
celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'))
|
||||
|
||||
# Connect to blockchain with chainlib
|
||||
rpc = RPCConnection.connect(chain_spec, 'default')
|
||||
|
||||
o = block_latest()
|
||||
r = rpc.do(o)
|
||||
@ -151,7 +158,8 @@ def main():
|
||||
|
||||
tx_filter = TxFilter(chain_spec, config.get('_CELERY_QUEUE'))
|
||||
|
||||
registration_filter = RegistrationFilter(chain_spec, config.get('_CELERY_QUEUE'))
|
||||
account_registry_address = registry.by_name('AccountRegistry')
|
||||
registration_filter = RegistrationFilter(chain_spec, account_registry_address, queue=config.get('_CELERY_QUEUE'))
|
||||
|
||||
gas_filter = GasFilter(chain_spec, config.get('_CELERY_QUEUE'))
|
||||
|
||||
|
@ -13,3 +13,4 @@ erc20-faucet~=0.2.2a1
|
||||
erc20-transfer-authorization~=0.3.2a1
|
||||
sarafu-faucet~=0.0.4a1
|
||||
moolb~=0.1.1b2
|
||||
erc20-transfer-authorization~=0.3.2a1
|
||||
|
@ -18,6 +18,7 @@ def test_filter_bogus(
|
||||
cic_registry,
|
||||
contract_roles,
|
||||
register_lookups,
|
||||
account_registry,
|
||||
):
|
||||
|
||||
fltrs = [
|
||||
@ -26,7 +27,7 @@ def test_filter_bogus(
|
||||
TxFilter(default_chain_spec, None),
|
||||
CallbackFilter(default_chain_spec, None, None, caller_address=contract_roles['CONTRACT_DEPLOYER']),
|
||||
StragglerFilter(default_chain_spec, None),
|
||||
RegistrationFilter(default_chain_spec, queue=None),
|
||||
RegistrationFilter(default_chain_spec, account_registry, queue=None),
|
||||
]
|
||||
|
||||
for fltr in fltrs:
|
||||
|
@ -1,3 +1,7 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import os
|
||||
|
||||
# external imports
|
||||
from eth_accounts_index.registry import AccountRegistry
|
||||
from chainlib.connection import RPCConnection
|
||||
@ -14,12 +18,17 @@ from chainlib.eth.block import (
|
||||
Block,
|
||||
)
|
||||
from erc20_faucet import Faucet
|
||||
from hexathon import strip_0x
|
||||
from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
)
|
||||
from chainqueue.sql.query import get_account_tx
|
||||
|
||||
# local imports
|
||||
from cic_eth.runnable.daemons.filters.register import RegistrationFilter
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_register_filter(
|
||||
default_chain_spec,
|
||||
@ -60,7 +69,11 @@ def test_register_filter(
|
||||
tx = Tx(tx_src, block=block, rcpt=rcpt)
|
||||
tx.apply_receipt(rcpt)
|
||||
|
||||
fltr = RegistrationFilter(default_chain_spec, queue=None)
|
||||
fltr = RegistrationFilter(default_chain_spec, add_0x(os.urandom(20).hex()), queue=None)
|
||||
t = fltr.filter(eth_rpc, block, tx, db_session=init_database)
|
||||
assert t == None
|
||||
|
||||
fltr = RegistrationFilter(default_chain_spec, account_registry, queue=None)
|
||||
t = fltr.filter(eth_rpc, block, tx, db_session=init_database)
|
||||
|
||||
t.get_leaf()
|
||||
|
Loading…
Reference in New Issue
Block a user