2021-03-30 18:33:09 +02:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# external imports
|
|
|
|
from cic_eth_registry import CICRegistry
|
|
|
|
from cic_eth_registry.lookup.declarator import AddressDeclaratorLookup
|
|
|
|
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
|
2021-05-27 15:27:38 +02:00
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
2021-03-30 18:33:09 +02:00
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
2021-05-27 15:27:38 +02:00
|
|
|
def connect_token_registry(rpc, chain_spec, sender_address=ZERO_ADDRESS):
|
2021-03-30 18:33:09 +02:00
|
|
|
registry = CICRegistry(chain_spec, rpc)
|
2021-05-27 15:27:38 +02:00
|
|
|
token_registry_address = registry.by_name('TokenRegistry', sender_address=sender_address)
|
2021-03-30 18:33:09 +02:00
|
|
|
logg.debug('using token registry address {}'.format(token_registry_address))
|
2021-04-04 14:40:59 +02:00
|
|
|
lookup = TokenIndexLookup(chain_spec, token_registry_address)
|
2021-03-30 18:33:09 +02:00
|
|
|
CICRegistry.add_lookup(lookup)
|
|
|
|
|
|
|
|
|
2021-05-27 15:27:38 +02:00
|
|
|
def connect_declarator(rpc, chain_spec, trusted_addresses, sender_address=ZERO_ADDRESS):
|
2021-03-30 18:33:09 +02:00
|
|
|
registry = CICRegistry(chain_spec, rpc)
|
2021-05-27 15:27:38 +02:00
|
|
|
declarator_address = registry.by_name('AddressDeclarator', sender_address=sender_address)
|
2021-03-30 18:33:09 +02:00
|
|
|
logg.debug('using declarator address {}'.format(declarator_address))
|
2021-04-04 14:40:59 +02:00
|
|
|
lookup = AddressDeclaratorLookup(chain_spec, declarator_address, trusted_addresses)
|
2021-03-30 18:33:09 +02:00
|
|
|
CICRegistry.add_lookup(lookup)
|
|
|
|
|
|
|
|
|
2021-05-27 15:27:38 +02:00
|
|
|
def connect(rpc, chain_spec, registry_address, sender_address=ZERO_ADDRESS):
|
2021-03-30 18:33:09 +02:00
|
|
|
CICRegistry.address = registry_address
|
|
|
|
registry = CICRegistry(chain_spec, rpc)
|
2021-05-27 15:27:38 +02:00
|
|
|
registry_address = registry.by_name('ContractRegistry', sender_address=sender_address)
|
2021-03-30 18:33:09 +02:00
|
|
|
return registry
|
2021-04-25 14:24:17 +02:00
|
|
|
|