1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_binary, Addr, Binary, Coin, CosmosMsg, StdResult, WasmMsg};
use cw20::Cw20CoinVerified;

use crate::types::AmountForOneTask;

#[cw_serde]
pub struct ManagerRemoveTask {
    pub sender: Addr,
    pub task_hash: Vec<u8>,
}

impl ManagerRemoveTask {
    /// serializes the message
    pub fn into_binary(self) -> StdResult<Binary> {
        let msg = RemoveTaskMsg::RemoveTask(self);
        to_binary(&msg)
    }

    /// creates a cosmos_msg sending this struct to the named contract
    pub fn into_cosmos_msg<T: Into<String>>(self, contract_addr: T) -> StdResult<CosmosMsg> {
        let msg = self.into_binary()?;
        let execute = WasmMsg::Execute {
            contract_addr: contract_addr.into(),
            msg,
            funds: vec![],
        };
        Ok(execute.into())
    }
}

// This is just a helper to properly serialize the above message
#[cw_serde]
enum RemoveTaskMsg {
    RemoveTask(ManagerRemoveTask),
}

// Note: sender and cw20 validated on the tasks contract
#[cw_serde]
pub struct ManagerCreateTaskBalance {
    pub sender: Addr,
    pub task_hash: Vec<u8>,
    pub recurring: bool,
    pub cw20: Option<Cw20CoinVerified>,
    pub amount_for_one_task: AmountForOneTask,
}

impl ManagerCreateTaskBalance {
    /// serializes the message
    pub fn into_binary(self) -> StdResult<Binary> {
        let msg = CreateTaskBalanceMsg::CreateTaskBalance(self);
        to_binary(&msg)
    }

    /// creates a cosmos_msg sending this struct to the named contract
    pub fn into_cosmos_msg<T: Into<String>>(
        self,
        contract_addr: T,
        funds: Vec<Coin>,
    ) -> StdResult<CosmosMsg> {
        let msg = self.into_binary()?;
        let execute = WasmMsg::Execute {
            contract_addr: contract_addr.into(),
            msg,
            funds,
        };
        Ok(execute.into())
    }
}

#[cw_serde]
enum CreateTaskBalanceMsg {
    CreateTaskBalance(ManagerCreateTaskBalance),
}