terra_rust_api/messages/
bank.rs

1//use crate::client::client_types::terra_u64_format;
2use crate::core_types::{Coin, MsgInternal};
3
4use crate::errors::TerraRustAPIError;
5use crate::messages::Message;
6use serde::Serialize;
7
8#[derive(Serialize, Debug)]
9/// Message: Send N coins from an address to another
10
11pub struct MsgSend {
12    pub amount: Vec<Coin>,
13    pub from_address: String,
14    pub to_address: String,
15}
16
17impl MsgInternal for MsgSend {}
18impl MsgSend {
19    /// Send amount coins from from_address to to_address
20    pub fn create_single(
21        from_address: String,
22        to_address: String,
23        amount: Coin,
24    ) -> Result<Message, TerraRustAPIError> {
25        MsgSend::create(from_address, to_address, vec![amount])
26    }
27    /// send multiple coins from from_address to to_address
28    pub fn create(
29        from_address: String,
30        to_address: String,
31        amount: Vec<Coin>,
32    ) -> Result<Message, TerraRustAPIError> {
33        let internal = MsgSend {
34            amount,
35            from_address,
36            to_address,
37        };
38        Ok(Message {
39            s_type: "bank/MsgSend".into(),
40            value: serde_json::to_value(internal)?,
41        })
42    }
43}