Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not merge] Refactor (protocol.py): Clean patches #433

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions operate/services/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,6 @@ def __init__(
self.wallet = wallet
self.contracts = contracts
self.chain_type = chain_type or ChainType.CUSTOM

def _patch(self) -> None:
"""Patch contract and chain config."""
ChainConfigs.get(self.chain_type).rpc = self.rpc
if self.chain_type != ChainType.CUSTOM:
return
Expand All @@ -533,7 +530,6 @@ def safe(self) -> str:
@property
def crypto(self) -> Crypto:
"""Load crypto object."""
self._patch()
_, crypto = OnChainHelper.get_ledger_and_crypto_objects(
chain_type=self.chain_type,
key=self.wallet.key_path,
Expand All @@ -544,7 +540,6 @@ def crypto(self) -> Crypto:
@property
def ledger_api(self) -> LedgerApi:
"""Load ledger api object."""
self._patch()
ledger_api, _ = OnChainHelper.get_ledger_and_crypto_objects(
chain_type=self.chain_type,
key=self.wallet.key_path,
Expand All @@ -566,7 +561,6 @@ def service_manager_instance(self) -> Contract:

def owner_of(self, token_id: int) -> str:
"""Get owner of a service."""
self._patch()
ledger_api, _ = OnChainHelper.get_ledger_and_crypto_objects(
chain_type=self.chain_type
)
Expand All @@ -577,7 +571,6 @@ def owner_of(self, token_id: int) -> str:

def info(self, token_id: int) -> t.Dict:
"""Get service info."""
self._patch()
ledger_api, _ = OnChainHelper.get_ledger_and_crypto_objects(
chain_type=self.chain_type
)
Expand Down Expand Up @@ -614,7 +607,6 @@ def info(self, token_id: int) -> t.Dict:

def get_agent_bond(self, service_id: int, agent_id: int) -> int:
"""Get the agent bond for a given service"""
self._patch()

if service_id <= 0 or agent_id <= 0:
return 0
Expand Down Expand Up @@ -659,7 +651,6 @@ def swap( # pylint: disable=too-many-arguments,too-many-locals
) -> None:
"""Swap safe owner."""
logging.info(f"Swapping safe for service {service_id} [{multisig}]...")
self._patch()
manager = ServiceManager(
service_id=service_id,
chain_type=self.chain_type,
Expand Down Expand Up @@ -747,7 +738,6 @@ def swap( # pylint: disable=too-many-arguments,too-many-locals

def staking_slots_available(self, staking_contract: str) -> bool:
"""Check if there are available slots on the staking contract"""
self._patch()
return StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -758,7 +748,6 @@ def staking_slots_available(self, staking_contract: str) -> bool:

def staking_rewards_available(self, staking_contract: str) -> bool:
"""Check if there are available staking rewards on the staking contract"""
self._patch()
available_rewards = StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -770,7 +759,6 @@ def staking_rewards_available(self, staking_contract: str) -> bool:

def staking_status(self, service_id: int, staking_contract: str) -> StakingState:
"""Stake the service"""
self._patch()
return StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -782,7 +770,6 @@ def staking_status(self, service_id: int, staking_contract: str) -> StakingState

def get_staking_params(self, staking_contract: str) -> t.Dict:
"""Get agent IDs for the staking contract"""
self._patch()
staking_manager = StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand Down Expand Up @@ -846,7 +833,6 @@ def mint( # pylint: disable=too-many-arguments,too-many-locals
) -> t.Dict:
"""Mint service."""
# TODO: Support for update
self._patch()
manager = MintManager(
chain_type=self.chain_type,
key=self.wallet.key_path,
Expand Down Expand Up @@ -902,7 +888,6 @@ def activate(
) -> None:
"""Activate service."""
logging.info(f"Activating service {service_id}...")
self._patch()
with contextlib.redirect_stdout(io.StringIO()):
ServiceManager(
service_id=service_id,
Expand Down Expand Up @@ -949,7 +934,6 @@ def deploy(
) -> None:
"""Deploy service."""
logging.info(f"Deploying service {service_id}...")
self._patch()
with contextlib.redirect_stdout(io.StringIO()):
ServiceManager(
service_id=service_id,
Expand All @@ -968,7 +952,6 @@ def deploy(
def terminate(self, service_id: int, token: t.Optional[str] = None) -> None:
"""Terminate service."""
logging.info(f"Terminating service {service_id}...")
self._patch()
with contextlib.redirect_stdout(io.StringIO()):
ServiceManager(
service_id=service_id,
Expand All @@ -985,7 +968,6 @@ def terminate(self, service_id: int, token: t.Optional[str] = None) -> None:
def unbond(self, service_id: int, token: t.Optional[str] = None) -> None:
"""Unbond service."""
logging.info(f"Unbonding service {service_id}...")
self._patch()
with contextlib.redirect_stdout(io.StringIO()):
ServiceManager(
service_id=service_id,
Expand All @@ -1006,7 +988,6 @@ def stake(
staking_contract: str,
) -> None:
"""Stake service."""
self._patch()
StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -1019,7 +1000,6 @@ def stake(

def unstake(self, service_id: int, staking_contract: str) -> None:
"""Unstake service."""
self._patch()
StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -1031,7 +1011,6 @@ def unstake(self, service_id: int, staking_contract: str) -> None:

def staking_status(self, service_id: int, staking_contract: str) -> StakingState:
"""Stake the service"""
self._patch()
return StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand Down Expand Up @@ -1067,7 +1046,6 @@ def get_mint_tx_data( # pylint: disable=too-many-arguments
) -> t.Dict:
"""Build mint transaction."""
# TODO: Support for update
self._patch()
manager = MintManager(
chain_type=self.chain_type,
key=self.wallet.key_path,
Expand Down Expand Up @@ -1328,7 +1306,6 @@ def get_staking_approval_data(
staking_contract: str,
) -> t.Dict:
"""Get staking approval data"""
self._patch()
txd = StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -1352,7 +1329,6 @@ def get_staking_data(
staking_contract: str,
) -> t.Dict:
"""Get staking tx data"""
self._patch()
txd = StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -1374,7 +1350,6 @@ def get_unstaking_data(
staking_contract: str,
) -> t.Dict:
"""Get unstaking tx data"""
self._patch()
txd = StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand All @@ -1392,7 +1367,6 @@ def get_unstaking_data(

def staking_slots_available(self, staking_contract: str) -> bool:
"""Stake service."""
self._patch()
return StakingManager(
key=self.wallet.key_path,
password=self.wallet.password,
Expand Down
Loading