abstract_sdk/
account_action.rs1use cosmwasm_std::CosmosMsg;
2
3#[derive(Debug, Default, PartialEq, Clone)]
8#[must_use = "Pass AccountAction to the Executor, see the docs"]
9pub struct AccountAction(Vec<CosmosMsg>);
10
11impl AccountAction {
12 pub fn messages(&self) -> Vec<CosmosMsg> {
15 self.0.clone()
16 }
17
18 pub fn merge(&mut self, other: AccountAction) {
20 self.0.extend(other.0)
21 }
22
23 pub fn from_vec<T>(msgs: Vec<T>) -> Self
25 where
26 T: Into<CosmosMsg>,
27 {
28 Self(msgs.into_iter().map(Into::into).collect())
29 }
30}
31
32impl<T> From<T> for AccountAction
33where
34 T: Into<CosmosMsg>,
35{
36 fn from(m: T) -> Self {
37 Self(vec![m.into()])
38 }
39}
40
41#[cfg(test)]
42mod test {
43 use cosmwasm_std::coins;
44
45 use super::*;
46
47 #[coverage_helper::test]
48 fn account_action() {
49 let mut account_action =
50 AccountAction::from_vec(vec![CosmosMsg::Bank(cosmwasm_std::BankMsg::Burn {
51 amount: coins(5, "test"),
52 })]);
53 assert_eq!(
54 account_action.messages(),
55 vec![CosmosMsg::Bank(cosmwasm_std::BankMsg::Burn {
56 amount: coins(5, "test"),
57 })]
58 );
59
60 account_action.merge(account_action.clone());
62 assert_eq!(
63 account_action.messages(),
64 vec![
65 CosmosMsg::Bank(cosmwasm_std::BankMsg::Burn {
66 amount: coins(5, "test"),
67 }),
68 CosmosMsg::Bank(cosmwasm_std::BankMsg::Burn {
69 amount: coins(5, "test"),
70 })
71 ]
72 )
73 }
74}