layer_climb_core/signing/contract/
msg.rs

1use anyhow::Result;
2use serde::Serialize;
3
4use crate::{contract_helpers::contract_msg_to_vec, prelude::*};
5
6impl SigningClient {
7    pub fn contract_upload_file_msg(
8        &self,
9        wasm_byte_code: Vec<u8>,
10    ) -> Result<layer_climb_proto::wasm::MsgStoreCode> {
11        Ok(layer_climb_proto::wasm::MsgStoreCode {
12            sender: self.addr.to_string(),
13            wasm_byte_code,
14            instantiate_permission: None,
15        })
16    }
17
18    pub fn contract_instantiate_msg(
19        &self,
20        admin: impl Into<Option<Address>>,
21        code_id: u64,
22        label: impl ToString,
23        funds: Vec<layer_climb_proto::Coin>,
24        msg: &impl Serialize,
25    ) -> Result<layer_climb_proto::wasm::MsgInstantiateContract> {
26        Ok(layer_climb_proto::wasm::MsgInstantiateContract {
27            sender: self.addr.to_string(),
28            admin: admin.into().map(|a| a.to_string()).unwrap_or_default(),
29            code_id,
30            label: label.to_string(),
31            msg: contract_msg_to_vec(msg)?,
32            funds,
33        })
34    }
35
36    pub fn contract_execute_msg(
37        &self,
38        address: &Address,
39        funds: Vec<layer_climb_proto::Coin>,
40        msg: &impl Serialize,
41    ) -> Result<layer_climb_proto::wasm::MsgExecuteContract> {
42        Ok(layer_climb_proto::wasm::MsgExecuteContract {
43            sender: self.addr.to_string(),
44            contract: address.to_string(),
45            msg: contract_msg_to_vec(msg)?,
46            funds,
47        })
48    }
49
50    pub fn contract_migrate_msg(
51        &self,
52        address: &Address,
53        code_id: u64,
54        msg: &impl Serialize,
55    ) -> Result<layer_climb_proto::wasm::MsgMigrateContract> {
56        Ok(layer_climb_proto::wasm::MsgMigrateContract {
57            sender: self.addr.to_string(),
58            contract: address.to_string(),
59            code_id,
60            msg: contract_msg_to_vec(msg)?,
61        })
62    }
63}