Skip to content

Commit 8f8f0ef

Browse files
authored
Merge pull request #2202 from CosmWasm/document-CustomMsg
Document CustomMsg
2 parents 05f77ed + b48a069 commit 8f8f0ef

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

packages/std/src/results/cosmos_msg.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,36 @@ use crate::{to_json_binary, Binary};
1616

1717
use super::Empty;
1818

19-
/// Like CustomQuery for better type clarity.
20-
/// Also makes it shorter to use as a trait bound.
19+
/// A trait for custom message types which are embedded in `CosmosMsg::Custom(..)`.
20+
/// Those are messages that the contract and the chain need
21+
/// to agree on in advance as the chain must be able to deserialize and execute them.
22+
///
23+
/// Custom messages are always JSON-encoded when sent from the contract to the environment.
24+
///
25+
/// This trait is similar to [`CustomQuery`](crate::CustomQuery) for better type clarity and
26+
/// makes it shorter to use as a trait bound. It does not require fields or functions to be implemented.
27+
///
28+
/// An alternative approach is using [`CosmosMsg::Any`][crate::CosmosMsg#variant.Any]
29+
/// which provides more flexibility but offers less type-safety.
30+
///
31+
/// ## Examples
32+
///
33+
/// Some real-world examples of such custom message types are
34+
/// [TgradeMsg](https://github.com/confio/poe-contracts/blob/v0.17.1/packages/bindings/src/msg.rs#L13),
35+
/// [ArchwayMsg](https://github.com/archway-network/arch3.rs/blob/bindings/v0.2.1/packages/bindings/src/msg.rs#L22) or
36+
/// [NeutronMsg](https://github.com/neutron-org/neutron-sdk/blob/v0.11.0/packages/neutron-sdk/src/bindings/msg.rs#L33).
37+
///
38+
/// ```
39+
/// use cosmwasm_schema::cw_serde;
40+
/// use cosmwasm_std::CustomQuery;
41+
///
42+
/// #[cw_serde]
43+
/// pub enum MyMsg {
44+
/// // ...
45+
/// }
46+
///
47+
/// impl CustomQuery for MyMsg {}
48+
/// ```
2149
pub trait CustomMsg: Serialize + Clone + fmt::Debug + PartialEq + JsonSchema {}
2250

2351
impl CustomMsg for Empty {}

0 commit comments

Comments
 (0)