cic-cli/cic/ext/eth/start.py

35 lines
1.1 KiB
Python
Raw Normal View History

2021-10-18 10:47:48 +02:00
# external imports
from chainlib.eth.connection import RPCConnection
2022-02-10 09:22:21 +01:00
from cic_eth_registry import CICRegistry
2021-10-18 10:47:48 +02:00
def extension_start(network, *args, **kwargs):
"""Called by the "export" cli tool subcommand for initialization of the eth extension.
:param network: Network object to read and write settings from
:type network: cic.network.Network
"""
2022-02-10 09:22:21 +01:00
CICRegistry.address = kwargs["registry_address"]
key_account_address = kwargs["key_account_address"] or ""
RPCConnection.register_location(kwargs["rpc_provider"], kwargs["chain_spec"])
conn = RPCConnection.connect(kwargs["chain_spec"])
2021-10-18 10:47:48 +02:00
2022-02-10 09:22:21 +01:00
registry = CICRegistry(kwargs["chain_spec"], conn)
2021-10-18 10:47:48 +02:00
2022-02-10 09:22:21 +01:00
address_declarator = registry.by_name("AddressDeclarator")
network.resource_set(
"eth", "address_declarator", address_declarator, key_account=key_account_address
)
2021-10-18 10:47:48 +02:00
2022-02-10 09:22:21 +01:00
token_index = registry.by_name("TokenRegistry")
network.resource_set(
"eth", "token_index", token_index, key_account=key_account_address
)
2021-10-18 10:47:48 +02:00
2022-02-10 09:22:21 +01:00
network.resource_set("eth", "token", None, key_account=key_account_address)
2021-10-18 10:47:48 +02:00
2022-02-10 09:22:21 +01:00
network.set("eth", kwargs["chain_spec"])
2021-10-18 10:47:48 +02:00
network.save()