|
27 | 27 | from typing import Any, Dict, Generator, List, Optional, Tuple |
28 | 28 |
|
29 | 29 | from packages.valory.contracts.agent_registry.contract import AgentRegistryContract |
| 30 | +from packages.valory.contracts.complementary_service_metadata.contract import ( |
| 31 | + ComplementaryServiceMetadata, |
| 32 | +) |
30 | 33 | from packages.valory.protocols.contract_api import ContractApiMessage |
31 | 34 | from packages.valory.skills.abstract_round_abci.base import get_name |
32 | 35 | from packages.valory.skills.decision_maker_abci.behaviours.base import ( |
@@ -55,9 +58,7 @@ def __init__(self, **kwargs: Any) -> None: |
55 | 58 | """Initialize Behaviour.""" |
56 | 59 | super().__init__(**kwargs) |
57 | 60 | self._mech_id: int = 0 |
58 | | - self._mech_hash: str = ( |
59 | | - "d26821719fcdb05d3683d8091ca31183ccdb02b792abe9e69bd62e3886abe835" |
60 | | - ) |
| 61 | + self._mech_hash: str = "" |
61 | 62 | self._utilized_tools: Dict[str, str] = {} |
62 | 63 | self._mech_tools: Optional[List[str]] = None |
63 | 64 | self._remote_accuracy_information: StringIO = StringIO() |
@@ -131,8 +132,12 @@ def setup(self) -> None: |
131 | 132 |
|
132 | 133 | def set_mech_agent_specs(self) -> None: |
133 | 134 | """Set the mech's agent specs.""" |
134 | | - full_ipfs_hash = CID_PREFIX + self.mech_hash |
135 | | - ipfs_link = self.params.ipfs_address + full_ipfs_hash |
| 135 | + ipfs_link = ( |
| 136 | + self.mech_hash |
| 137 | + if self.params.use_mech_marketplace |
| 138 | + else self.params.ipfs_address + CID_PREFIX + self.mech_hash |
| 139 | + ) |
| 140 | + |
136 | 141 | # The url needs to be dynamically generated as it depends on the ipfs hash |
137 | 142 | self.mech_tools_api.__dict__["_frozen"] = False |
138 | 143 | self.mech_tools_api.url = ipfs_link |
@@ -180,6 +185,29 @@ def _get_mech_hash(self) -> WaitableConditionType: |
180 | 185 | ) |
181 | 186 | return result |
182 | 187 |
|
| 188 | + def _get_mech_service_id(self) -> WaitableConditionType: |
| 189 | + """Get the mech's id.""" |
| 190 | + result = yield from self._mech_mm_contract_interact( |
| 191 | + contract_callable="get_service_id", |
| 192 | + data_key="service_id", |
| 193 | + placeholder=get_name(StorageManagerBehaviour.mech_id), |
| 194 | + ) |
| 195 | + |
| 196 | + return result |
| 197 | + |
| 198 | + def _get_metadata_uri(self) -> WaitableConditionType: |
| 199 | + """Get the mech's hash.""" |
| 200 | + result = yield from self.contract_interact( |
| 201 | + performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore |
| 202 | + contract_address=self.params.metadata_address, |
| 203 | + contract_public_id=ComplementaryServiceMetadata.contract_id, |
| 204 | + contract_callable="get_token_uri", |
| 205 | + data_key="uri", |
| 206 | + placeholder=get_name(StorageManagerBehaviour.mech_hash), |
| 207 | + service_id=self.mech_id, |
| 208 | + ) |
| 209 | + return result |
| 210 | + |
183 | 211 | def _get_mech_tools(self) -> WaitableConditionType: |
184 | 212 | """Get the mech agent's tools from IPFS.""" |
185 | 213 | self.set_mech_agent_specs() |
@@ -222,7 +250,23 @@ def _get_tools( |
222 | 250 | self._get_tools_from_benchmark_file() |
223 | 251 | return |
224 | 252 |
|
225 | | - yield from self.wait_for_condition_with_sleep(self._get_mech_tools) |
| 253 | + metadata_steps = ( |
| 254 | + ( |
| 255 | + self._get_mech_service_id, |
| 256 | + self._get_metadata_uri, |
| 257 | + ) |
| 258 | + if self.params.use_mech_marketplace |
| 259 | + else ( |
| 260 | + self._get_mech_id, |
| 261 | + self._get_mech_hash, |
| 262 | + ) |
| 263 | + ) |
| 264 | + |
| 265 | + for step in ( |
| 266 | + *metadata_steps, |
| 267 | + self._get_mech_tools, |
| 268 | + ): |
| 269 | + yield from self.wait_for_condition_with_sleep(step) |
226 | 270 |
|
227 | 271 | def _try_recover_policy(self) -> Optional[EGreedyPolicy]: |
228 | 272 | """Try to recover the policy from the policy store.""" |
|
0 commit comments