Skip to content

Commit

Permalink
Refactor generation of proxy info object into helper method.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed Oct 31, 2023
1 parent 617a8af commit bd11f53
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions deployment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,7 @@ def from_config(cls, config: typing.Dict) -> "ProxyParameters":
if CONTRACT_PROXY_KEY not in contract_data:
continue

proxy_data = contract_data[CONTRACT_PROXY_KEY] or dict()
container = None
if cls.CONTAINER_PROPERTY in proxy_data:
container = proxy_data[cls.CONTAINER_PROPERTY]

constructor_data = cls._default_proxy_parameters(contract_name)
if CONTRACT_CONSTRUCTOR_KEY in proxy_data:
for name, value in proxy_data[CONTRACT_CONSTRUCTOR_KEY].items():
constructor_data.update({name: value})

proxy_info = cls.ProxyInfo(
container_name=container, constructor_params=constructor_data
)

proxy_info = cls._generate_proxy_info(contract_data, contract_name)
contracts_proxy_info.update({contract_name: proxy_info})

return cls(contracts_proxy_info=contracts_proxy_info, constants=config.get("constants"))
Expand All @@ -371,6 +358,22 @@ def resolve(self, contract_name: str) -> typing.Tuple[ContractContainer, Ordered

return contract_container, resolved_params

@classmethod
def _generate_proxy_info(cls, contract_data, contract_name) -> ProxyInfo:
proxy_data = contract_data[CONTRACT_PROXY_KEY] or dict()

container = None
if cls.CONTAINER_PROPERTY in proxy_data:
container = proxy_data[cls.CONTAINER_PROPERTY]

constructor_data = cls._default_proxy_parameters(contract_name)
if CONTRACT_CONSTRUCTOR_KEY in proxy_data:
for name, value in proxy_data[CONTRACT_CONSTRUCTOR_KEY].items():
constructor_data.update({name: value})

proxy_info = cls.ProxyInfo(container_name=container, constructor_params=constructor_data)
return proxy_info

@classmethod
def _default_proxy_parameters(cls, contract_name: str) -> OrderedDict:
default_parameters = OrderedDict(
Expand Down

0 comments on commit bd11f53

Please sign in to comment.