-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix/perform work #105
Fix/perform work #105
Conversation
def build_safe_raw_tx( | ||
self, | ||
tx_params: Dict[str, Any], | ||
) -> Generator[None, None, Optional[str]]: | ||
"""Build safe raw tx hash""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still need to finish the bonding / activation and work transaction preparation. This is related to performatives and will also affect the tests, so next PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
address = self.synchronized_data.safe_contract_address | ||
contract_api_response = yield from self.get_contract_api_response( | ||
performative=ContractApiMessage.Performative.GET_STATE, # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. this should be GET_RAW_TRANSACTION
, but it affects all transaction producing behaviours hence addressing separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def process_payload(self, payload: BaseTxPayload) -> None: | ||
"""Process payload.""" | ||
raise NotImplementedError | ||
_ = (Event.INSUFFICIENT_FUNDS,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually unnecessary I think, can be caught via error performative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can prepare tx and submit to tx settlement, which will handle insufficient funds
agent-academy-2/packages/valory/skills/transaction_settlement_abci/behaviours.py
Lines 215 to 216 in 89ba928
if rpc_status == RPCResponseStatus.INSUFFICIENT_FUNDS: | |
# blacklist self. |
def build_safe_raw_tx( | ||
self, | ||
tx_params: Dict[str, Any], | ||
) -> Generator[None, None, Optional[str]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it is worth opening an issue on open-autonomy
to extract a skill for this since it is also being done in the price estimation skill?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, I don't understand it well enough. Why not as part of the tx settlement skill?
def _get_raw_work_transaction_hash(self) -> Generator[None, None, Optional[str]]: | ||
|
||
job_contract_api_response = yield from self.get_contract_api_response( | ||
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore | ||
contract_id=str(Keep3rTestJobContract.contract_id), | ||
contract_callable="work", | ||
contract_address=self.synchronized_data.current_job, | ||
sender_address=self.context.agent_address, | ||
) | ||
|
||
if ( | ||
job_contract_api_response.performative | ||
!= ContractApiMessage.Performative.RAW_TRANSACTION | ||
): # pragma: nocover | ||
self.context.logger.warning("get raw work transaction unsuccessful!") | ||
return None | ||
|
||
tx_params = job_contract_api_response.raw_transaction.body | ||
safe_contract_address = self.synchronized_data.safe_contract_address | ||
|
||
safe_contract_api_msg = yield from self.get_contract_api_response( | ||
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore | ||
contract_address=safe_contract_address, | ||
contract_id=str(GnosisSafeContract.contract_id), | ||
contract_callable="get_raw_safe_transaction_hash", | ||
to_address=tx_params["to_address"], | ||
value=tx_params["ether_value"], | ||
data=tx_params["data"], | ||
safe_tx_gas=tx_params["safe_tx_gas"], | ||
) | ||
if ( | ||
safe_contract_api_msg.performative | ||
!= ContractApiMessage.Performative.RAW_TRANSACTION | ||
): # pragma: nocover | ||
self.context.logger.warning("Get work transaction hash unsuccessful!") | ||
return None | ||
tx_hash = cast(str, job_contract_api_response.raw_transaction.body.pop("hash")) | ||
|
||
return tx_hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved here
agent-academy-2/packages/keep3r_co/skills/keep3r_job/behaviours.py
Lines 201 to 247 in 911bcec
def build_work_raw_tx( | |
self, job_address: str, address: str | |
) -> Generator[None, None, Optional[RawTx]]: | |
"""Build raw work transaction for a job contract""" | |
contract_api_response = yield from self.get_contract_api_response( | |
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, | |
contract_id=str(Keep3rTestJobContract.contract_id), | |
contract_callable="build_work_tx", | |
contract_address=job_address, | |
address=address, | |
) | |
if ( | |
contract_api_response.performative | |
!= ContractApiMessage.Performative.RAW_TRANSACTION | |
): | |
self.context.logger.error( | |
f"Failed build_work_raw_tx: {contract_api_response}" | |
) | |
return None | |
log_msg = f"`build_work_tx` contract api response on {contract_api_response}" | |
self.context.logger.info(f"{log_msg}: {contract_api_response}") | |
return cast(RawTx, contract_api_response.raw_transaction.body.get("data")) | |
def build_safe_raw_tx( | |
self, | |
tx_params: RawTx, | |
) -> Generator[None, None, Optional[str]]: | |
"""Build safe raw tx hash""" | |
contract_api_response = yield from self.get_contract_api_response( | |
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, | |
contract_address=self.synchronized_data.safe_contract_address, | |
contract_id=str(GnosisSafeContract.contract_id), | |
contract_callable="get_raw_safe_transaction_hash", | |
to_address=tx_params["to"], | |
value=tx_params["value"], | |
data=tx_params["data"], | |
safe_tx_gas=tx_params["gas"], | |
) | |
if ( | |
contract_api_response.performative | |
!= ContractApiMessage.Performative.RAW_TRANSACTION | |
): | |
self.context.logger.warning("build_safe_raw_tx unsuccessful!") | |
return None | |
return cast(str, contract_api_response.raw_transaction.body.pop("tx_hash")) |
@@ -129,6 +129,31 @@ def has_sufficient_funds(self, address: str) -> Generator[None, None, bool]: | |||
self.context.logger.info(f"balance: {balance / 10 ** 18} ETH") | |||
return balance >= cast(int, self.context.params.insufficient_funds_threshold) | |||
|
|||
def build_safe_raw_tx( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this being called anywhere in async_act
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests/performatives
Fix performatives
perform work round / behaviour. Still need to revisit performatives, #98 , which is up next.