croncat_sdk_core/internal_messages/
manager.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{to_binary, Addr, Binary, Coin, CosmosMsg, StdResult, WasmMsg};
3use cw20::Cw20CoinVerified;
4
5use crate::types::AmountForOneTask;
6
7#[cw_serde]
8pub struct ManagerRemoveTask {
9    pub sender: Addr,
10    pub task_hash: Vec<u8>,
11}
12
13impl ManagerRemoveTask {
14    /// serializes the message
15    pub fn into_binary(self) -> StdResult<Binary> {
16        let msg = RemoveTaskMsg::RemoveTask(self);
17        to_binary(&msg)
18    }
19
20    /// creates a cosmos_msg sending this struct to the named contract
21    pub fn into_cosmos_msg<T: Into<String>>(self, contract_addr: T) -> StdResult<CosmosMsg> {
22        let msg = self.into_binary()?;
23        let execute = WasmMsg::Execute {
24            contract_addr: contract_addr.into(),
25            msg,
26            funds: vec![],
27        };
28        Ok(execute.into())
29    }
30}
31
32// This is just a helper to properly serialize the above message
33#[cw_serde]
34enum RemoveTaskMsg {
35    RemoveTask(ManagerRemoveTask),
36}
37
38// Note: sender and cw20 validated on the tasks contract
39#[cw_serde]
40pub struct ManagerCreateTaskBalance {
41    pub sender: Addr,
42    pub task_hash: Vec<u8>,
43    pub recurring: bool,
44    pub cw20: Option<Cw20CoinVerified>,
45    pub amount_for_one_task: AmountForOneTask,
46}
47
48impl ManagerCreateTaskBalance {
49    /// serializes the message
50    pub fn into_binary(self) -> StdResult<Binary> {
51        let msg = CreateTaskBalanceMsg::CreateTaskBalance(self);
52        to_binary(&msg)
53    }
54
55    /// creates a cosmos_msg sending this struct to the named contract
56    pub fn into_cosmos_msg<T: Into<String>>(
57        self,
58        contract_addr: T,
59        funds: Vec<Coin>,
60    ) -> StdResult<CosmosMsg> {
61        let msg = self.into_binary()?;
62        let execute = WasmMsg::Execute {
63            contract_addr: contract_addr.into(),
64            msg,
65            funds,
66        };
67        Ok(execute.into())
68    }
69}
70
71#[cw_serde]
72enum CreateTaskBalanceMsg {
73    CreateTaskBalance(ManagerCreateTaskBalance),
74}