Skip to content

Commit

Permalink
fix: linters
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoreira-valory committed Aug 22, 2024
1 parent 6ccf856 commit bcd3a13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
7 changes: 4 additions & 3 deletions operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ async def _create_services(request: Request) -> JSONResponse:
if template.get("deploy", False):

def _fn() -> None:
# deploy_service_onchain_from_safe includes stake_service_on_chain_from_safe
manager.deploy_service_onchain_from_safe(hash=service.hash)
# manager.stake_service_on_chain_from_safe(hash=service.hash) # Done inside deploy_service_onchain
manager.fund_service(hash=service.hash)
manager.deploy_service_locally(hash=service.hash)

Expand All @@ -556,8 +556,9 @@ async def _update_services(request: Request) -> JSONResponse:
)
if template.get("deploy", False):
manager = operate.service_manager()

# deploy_service_onchain_from_safe includes stake_service_on_chain_from_safe
manager.deploy_service_onchain_from_safe(hash=service.hash)
# manager.stake_service_on_chain_from_safe(hash=service.hash) # Done in deploy_service_onchain_from_safe
manager.fund_service(hash=service.hash)
manager.deploy_service_locally(hash=service.hash)
schedule_funding_job(service=service.hash)
Expand Down Expand Up @@ -675,7 +676,7 @@ async def _start_service_locally(request: Request) -> JSONResponse:

def _fn() -> None:
manager.deploy_service_onchain(hash=service)
# manager.stake_service_on_chain(hash=service)
manager.stake_service_on_chain(hash=service)
manager.fund_service(hash=service)
manager.deploy_service_locally(hash=service, force=True)

Expand Down
33 changes: 17 additions & 16 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,21 @@ def load_or_create(

return service

def _get_on_chain_state(self, chain_config: ChainConfig) -> OnChainState:
def _get_on_chain_state(self, service: Service, chain_id: str) -> OnChainState:
chain_config = service.chain_configs[chain_id]
chain_data = chain_config.chain_data
ledger_config = chain_config.ledger_config
if chain_data.token == NON_EXISTENT_TOKEN:
service_state = OnChainState.NON_EXISTENT
chain_data.on_chain_state = service_state
# TODO save service state
# service.store()
service.store()
return service_state

sftxb = self.get_eth_safe_tx_builder(ledger_config=ledger_config)
info = sftxb.info(token_id=chain_data.token)
service_state = OnChainState(info["service_state"])
chain_data.on_chain_state = service_state
# TODO save service state
# service.store()
service.store()
return service_state

def _get_on_chain_hash(self, chain_config: ChainConfig) -> t.Optional[str]:
Expand Down Expand Up @@ -478,7 +477,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to

on_chain_hash = self._get_on_chain_hash(chain_config=chain_config)
is_first_mint = (
self._get_on_chain_state(chain_config=chain_config)
self._get_on_chain_state(service=service, chain_id=chain_id)
== OnChainState.NON_EXISTENT
)
is_update = (
Expand Down Expand Up @@ -507,7 +506,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to

# Update service
if (
self._get_on_chain_state(chain_config=chain_config)
self._get_on_chain_state(service=service, chain_id=chain_id)
== OnChainState.PRE_REGISTRATION
):
self.logger.info("Updating service")
Expand Down Expand Up @@ -549,7 +548,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to

# Mint service
if (
self._get_on_chain_state(chain_config=chain_config)
self._get_on_chain_state(service=service, chain_id=chain_id)
== OnChainState.NON_EXISTENT
):
if user_params.use_staking and not sftxb.staking_slots_available(
Expand Down Expand Up @@ -598,7 +597,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to
service.store()

if (
self._get_on_chain_state(chain_config=chain_config)
self._get_on_chain_state(service=service, chain_id=chain_id)
== OnChainState.PRE_REGISTRATION
):
cost_of_bond = staking_params["min_staking_deposit"]
Expand Down Expand Up @@ -651,7 +650,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to
service.store()

if (
self._get_on_chain_state(chain_config=chain_config)
self._get_on_chain_state(service=service, chain_id=chain_id)
== OnChainState.ACTIVE_REGISTRATION
):
cost_of_bond = user_params.cost_of_bond
Expand Down Expand Up @@ -708,7 +707,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to
service.store()

if (
self._get_on_chain_state(chain_config=chain_config)
self._get_on_chain_state(service=service, chain_id=chain_id)
== OnChainState.FINISHED_REGISTRATION
):
self.logger.info("Deploying service")
Expand Down Expand Up @@ -1007,7 +1006,7 @@ def stake_service_on_chain_from_safe(self, hash: str, chain_id: str) -> None:
target_staking_contract
)
staking_slots_available = sftxb.staking_slots_available(target_staking_contract)
on_chain_state = self._get_on_chain_state(chain_config=chain_config)
on_chain_state = self._get_on_chain_state(service=service, chain_id=chain_id)
current_staking_program = self._get_current_staking_program(
chain_data, ledger_config, sftxb
)
Expand Down Expand Up @@ -1260,12 +1259,14 @@ def update_service(
hash=new_hash, service_template=service_template
)
new_service.keys = old_service.keys
# new_Service.home_chain_id = old_service.home_chain_id

# TODO - Ensure this works as expected - New service must copy all chain_data from old service,
# but if service_template is not None, it must copy the user_params
# passed in the service_template and copy the remaining attributes from old_service.
# TODO Ensure this is as intended.
new_service.home_chain_id = old_service.home_chain_id

# new_service must copy all chain_data from old_service.
# Additionally, if service_template is not None, it must overwrite
# the user_params on all chain_data by the values passed through the
# service_template.
new_service.chain_configs = {}
for chain_id, config in old_service.chain_configs.items():
new_service.chain_configs[chain_id] = config
Expand Down
6 changes: 6 additions & 0 deletions operate/services/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,41 +244,47 @@ def service_info(self, staking_contract: str, service_id: int) -> dict:
).get("data")

def agent_ids(self, staking_contract: str) -> t.List[int]:
"""Get the agent IDs for the specified staking contract"""
instance = self.staking_ctr.get_instance(
ledger_api=self.ledger_api,
contract_address=staking_contract,
)
return instance.functions.getAgentIds().call()

def service_registry(self, staking_contract: str) -> str:
"""Get the service registry address for the specified staking contract"""
instance = self.staking_ctr.get_instance(
ledger_api=self.ledger_api,
contract_address=staking_contract,
)
return instance.functions.serviceRegistry().call()

def staking_token(self, staking_contract: str) -> str:
"""Get the staking token address for the specified staking contract"""
instance = self.staking_ctr.get_instance(
ledger_api=self.ledger_api,
contract_address=staking_contract,
)
return instance.functions.stakingToken().call()

def service_registry_token_utility(self, staking_contract: str) -> str:
"""Get the service registry token utility address for the specified staking contract"""
instance = self.staking_ctr.get_instance(
ledger_api=self.ledger_api,
contract_address=staking_contract,
)
return instance.functions.serviceRegistryTokenUtility().call()

def min_staking_deposit(self, staking_contract: str) -> str:
"""Get the minimum staking deposit for the specified staking contract"""
instance = self.staking_ctr.get_instance(
ledger_api=self.ledger_api,
contract_address=staking_contract,
)
return instance.functions.minStakingDeposit().call()

def activity_checker(self, staking_contract: str) -> str:
"""Get the activity checker address for the specified staking contract"""
instance = self.staking_ctr.get_instance(
ledger_api=self.ledger_api,
contract_address=staking_contract,
Expand Down

0 comments on commit bcd3a13

Please sign in to comment.