1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::{Addr, Binary, IbcAcknowledgement, Timestamp};
5
6#[non_exhaustive]
9#[derive(
10 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
11)]
12#[serde(rename_all = "snake_case")]
13pub struct Ibc2Payload {
14 pub source_port: String,
16 pub destination_port: String,
18 pub version: String,
20 pub encoding: String,
22 pub value: Binary,
24}
25
26impl Ibc2Payload {
27 pub fn new(
28 source_port: String,
29 destination_port: String,
30 version: String,
31 encoding: String,
32 value: Binary,
33 ) -> Self {
34 Self {
35 source_port,
36 destination_port,
37 version,
38 encoding,
39 value,
40 }
41 }
42}
43
44#[non_exhaustive]
47#[derive(
48 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
49)]
50#[serde(rename_all = "snake_case")]
51pub enum Ibc2Msg {
52 SendPacket {
54 source_client: String,
55 timeout: Timestamp,
56 payloads: Vec<Ibc2Payload>,
57 },
58 WriteAcknowledgement {
61 source_client: String,
63 destination_client: String,
65 packet_sequence: u64,
67 ack: IbcAcknowledgement,
69 },
70}
71
72#[derive(
76 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
77)]
78#[non_exhaustive]
79pub struct Ibc2PacketReceiveMsg {
80 pub payload: Ibc2Payload,
82 pub relayer: Addr,
84 pub source_client: String,
86 pub destination_client: String,
88 pub packet_sequence: u64,
90}
91
92impl Ibc2PacketReceiveMsg {
93 pub fn new(
94 payload: Ibc2Payload,
95 relayer: Addr,
96 source_client: String,
97 destination_client: String,
98 packet_sequence: u64,
99 ) -> Self {
100 Self {
101 payload,
102 relayer,
103 source_client,
104 destination_client,
105 packet_sequence,
106 }
107 }
108}
109
110#[derive(
115 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
116)]
117#[non_exhaustive]
118pub struct Ibc2PacketTimeoutMsg {
119 pub payload: Ibc2Payload,
121 pub source_client: String,
123 pub destination_client: String,
125 pub packet_sequence: u64,
127 pub relayer: Addr,
129}
130
131impl Ibc2PacketTimeoutMsg {
132 pub fn new(
133 payload: Ibc2Payload,
134 source_client: String,
135 destination_client: String,
136 packet_sequence: u64,
137 relayer: Addr,
138 ) -> Self {
139 Self {
140 payload,
141 source_client,
142 destination_client,
143 packet_sequence,
144 relayer,
145 }
146 }
147}
148
149#[derive(
151 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
152)]
153#[non_exhaustive]
154pub struct Ibc2PacketAckMsg {
155 pub source_client: String,
156 pub destination_client: String,
157 pub data: Ibc2Payload,
158 pub acknowledgement: Binary,
159 pub relayer: Addr,
160}
161
162impl Ibc2PacketAckMsg {
163 pub fn new(
164 source_client: String,
165 destination_client: String,
166 data: Ibc2Payload,
167 acknowledgement: Binary,
168 relayer: Addr,
169 ) -> Self {
170 Self {
171 source_client,
172 destination_client,
173 data,
174 acknowledgement,
175 relayer,
176 }
177 }
178}
179
180#[derive(
188 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
189)]
190#[non_exhaustive]
191pub struct Ibc2PacketSendMsg {
192 pub payload: Ibc2Payload,
194 pub source_client: String,
196 pub destination_client: String,
198 pub packet_sequence: u64,
200 pub signer: Addr,
202}
203
204impl Ibc2PacketSendMsg {
205 pub fn new(
206 payload: Ibc2Payload,
207 source_client: String,
208 destination_client: String,
209 packet_sequence: u64,
210 signer: Addr,
211 ) -> Self {
212 Self {
213 payload,
214 source_client,
215 destination_client,
216 packet_sequence,
217 signer,
218 }
219 }
220}
221
222#[cfg(test)]
223mod tests {
224 use serde_json::to_string;
225
226 use crate::Ibc2Payload;
227
228 #[test]
229 fn ibc2_payload_serialize() {
230 let packet = Ibc2Payload {
231 source_port: "sending-contractr-port".to_string(),
232 destination_port: "receiving-contract-port".to_string(),
233 version: "v1".to_string(),
234 encoding: "json".to_string(),
235 value: b"foo".into(),
236 };
237 let expected = r#"{"source_port":"sending-contractr-port","destination_port":"receiving-contract-port","version":"v1","encoding":"json","value":"Zm9v"}"#;
238 assert_eq!(to_string(&packet).unwrap(), expected);
239 }
240}