Skip to content

Commit

Permalink
Make grant_initiator_role script a common script and parameterize usi…
Browse files Browse the repository at this point in the history
…ng click options.

Fix bug in Transactor to set account when it is specified.
  • Loading branch information
derekpierre committed Oct 11, 2023
1 parent 39535d3 commit 1a53949
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
36 changes: 18 additions & 18 deletions deployment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -263,23 +261,23 @@ 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):
contract = {contract: 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

Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 1a53949

Please sign in to comment.