From 1a539496693cb25f2aa9da0fc8c25515f4e32817 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 10 Oct 2023 20:55:56 -0400 Subject: [PATCH] Make grant_initiator_role script a common script and parameterize using click options. Fix bug in Transactor to set account when it is specified. --- deployment/params.py | 36 ++++++++++----------- scripts/{tapir => }/grant_initiator_role.py | 23 +++++++++---- 2 files changed, 34 insertions(+), 25 deletions(-) rename scripts/{tapir => }/grant_initiator_role.py (50%) diff --git a/deployment/params.py b/deployment/params.py index b52864c4..b7176c9e 100644 --- a/deployment/params.py +++ b/deployment/params.py @@ -8,10 +8,6 @@ from ape.cli import get_user_selected_account from ape.contracts.base import ContractContainer, ContractInstance, ContractTransactionHandler from ape.utils import ZERO_ADDRESS -from eth_typing import ChecksumAddress -from ethpm_types import MethodABI -from web3.auto.gethdev import w3 - from deployment.confirm import _confirm_resolution, _continue from deployment.constants import ( BYTES_PREFIX, @@ -24,12 +20,14 @@ from deployment.registry import registry_from_ape_deployments from deployment.utils import ( _load_yaml, - verify_contracts, - get_contract_container, check_plugins, - get_artifact_filepath, - validate_config + get_contract_container, + validate_config, + verify_contracts, ) +from eth_typing import ChecksumAddress +from ethpm_types import MethodABI +from web3.auto.gethdev import w3 def _is_variable(param: Any) -> bool: @@ -263,15 +261,15 @@ def validate_constructor_parameters(config: typing.OrderedDict[str, Any]) -> Non contract_name=contract, abi_inputs=contract_container.constructor.abi.inputs, parameters=parameters, - ) + ) def _get_contracts_config(config: typing.Dict) -> OrderedDict: """Returns the contracts config from a constructor parameters file.""" try: - contracts = config['contracts'] + contracts = config["contracts"] except KeyError: - raise ValueError(f"Constructor parameters file missing 'contracts' field.") + raise ValueError("Constructor parameters file missing 'contracts' field.") result = OrderedDict() for contract in contracts: if isinstance(contract, str): @@ -279,7 +277,7 @@ def _get_contracts_config(config: typing.Dict) -> OrderedDict: elif isinstance(contract, dict): contract = OrderedDict(contract) else: - raise ValueError(f"Malformed constructor parameters YAML.") + raise ValueError("Malformed constructor parameters YAML.") result.update(contract) return result @@ -314,6 +312,8 @@ class Transactor: def __init__(self, account: typing.Optional[AccountAPI] = None): if account is None: self._account = get_user_selected_account() + else: + self._account = account def get_account(self) -> AccountAPI: """Returns the transactor account.""" @@ -347,11 +347,11 @@ class Deployer(Transactor): __DEPLOYER_ACCOUNT: AccountAPI = None def __init__( - self, - config: typing.Dict, - path: Path, - verify: bool, - account: typing.Optional[AccountAPI] = None + self, + config: typing.Dict, + path: Path, + verify: bool, + account: typing.Optional[AccountAPI] = None, ): check_plugins() self.path = path @@ -426,6 +426,6 @@ def _confirm_start(self) -> None: f"Network: {networks.provider.network.name}", f"Chain ID: {networks.provider.network.chain_id}", f"Gas Price: {networks.provider.gas_price}", - sep="\n" + sep="\n", ) _continue() diff --git a/scripts/tapir/grant_initiator_role.py b/scripts/grant_initiator_role.py similarity index 50% rename from scripts/tapir/grant_initiator_role.py rename to scripts/grant_initiator_role.py index c22928e4..71ce5571 100644 --- a/scripts/tapir/grant_initiator_role.py +++ b/scripts/grant_initiator_role.py @@ -1,20 +1,29 @@ #!/usr/bin/python3 +from pathlib import Path - +import click from ape import networks, project -from deployment.constants import ARTIFACTS_DIR +from ape.cli import NetworkBoundCommand, account_option, network_option from deployment.params import Transactor from deployment.registry import contracts_from_registry from deployment.utils import check_plugins -TAPIR_REGISTRY_FILEPATH = ARTIFACTS_DIR / "tapir.json" - -def main(): +@click.command(cls=NetworkBoundCommand) +@network_option(required=True) +@account_option() +@click.option( + "--registry-filepath", + "-r", + help="Filepath to registry file", + type=click.Path(dir_okay=False, exists=True, path_type=Path), + required=True, +) +def cli(network, account, registry_filepath): check_plugins() - transactor = Transactor() + transactor = Transactor(account) deployments = contracts_from_registry( - filepath=TAPIR_REGISTRY_FILEPATH, chain_id=networks.active_provider.chain_id + filepath=registry_filepath, chain_id=networks.active_provider.chain_id ) coordinator = deployments[project.Coordinator.contract_type.name] initiator_role_hash = coordinator.INITIATOR_ROLE()