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 packet_sequence: u64,
65 ack: IbcAcknowledgement,
67 },
68}
69
70#[derive(
74 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
75)]
76#[non_exhaustive]
77pub struct Ibc2PacketReceiveMsg {
78 pub payload: Ibc2Payload,
80 pub relayer: Addr,
82 pub source_client: String,
84 pub packet_sequence: u64,
86}
87
88impl Ibc2PacketReceiveMsg {
89 pub fn new(
90 payload: Ibc2Payload,
91 relayer: Addr,
92 source_client: String,
93 packet_sequence: u64,
94 ) -> Self {
95 Self {
96 payload,
97 relayer,
98 source_client,
99 packet_sequence,
100 }
101 }
102}
103
104#[derive(
109 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
110)]
111#[non_exhaustive]
112pub struct Ibc2PacketTimeoutMsg {
113 pub payload: Ibc2Payload,
115 pub source_client: String,
117 pub destination_client: String,
119 pub packet_sequence: u64,
121 pub relayer: Addr,
123}
124
125impl Ibc2PacketTimeoutMsg {
126 pub fn new(
127 payload: Ibc2Payload,
128 source_client: String,
129 destination_client: String,
130 packet_sequence: u64,
131 relayer: Addr,
132 ) -> Self {
133 Self {
134 payload,
135 source_client,
136 destination_client,
137 packet_sequence,
138 relayer,
139 }
140 }
141}
142
143#[derive(
145 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
146)]
147#[non_exhaustive]
148pub struct Ibc2PacketAckMsg {
149 pub source_client: String,
150 pub destination_client: String,
151 pub data: Ibc2Payload,
152 pub acknowledgement: Binary,
153 pub relayer: Addr,
154}
155
156impl Ibc2PacketAckMsg {
157 pub fn new(
158 source_client: String,
159 destination_client: String,
160 data: Ibc2Payload,
161 acknowledgement: Binary,
162 relayer: Addr,
163 ) -> Self {
164 Self {
165 source_client,
166 destination_client,
167 data,
168 acknowledgement,
169 relayer,
170 }
171 }
172}
173
174#[derive(
182 Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier, JsonSchema,
183)]
184#[non_exhaustive]
185pub struct Ibc2PacketSendMsg {
186 pub payload: Ibc2Payload,
188 pub source_client: String,
190 pub destination_client: String,
192 pub packet_sequence: u64,
194 pub signer: Addr,
196}
197
198impl Ibc2PacketSendMsg {
199 pub fn new(
200 payload: Ibc2Payload,
201 source_client: String,
202 destination_client: String,
203 packet_sequence: u64,
204 signer: Addr,
205 ) -> Self {
206 Self {
207 payload,
208 source_client,
209 destination_client,
210 packet_sequence,
211 signer,
212 }
213 }
214}
215
216#[cfg(test)]
217mod tests {
218 use serde_json::to_string;
219
220 use crate::Ibc2Payload;
221
222 #[test]
223 fn ibc2_payload_serialize() {
224 let packet = Ibc2Payload {
225 source_port: "sending-contractr-port".to_string(),
226 destination_port: "receiving-contract-port".to_string(),
227 version: "v1".to_string(),
228 encoding: "json".to_string(),
229 value: b"foo".into(),
230 };
231 let expected = r#"{"source_port":"sending-contractr-port","destination_port":"receiving-contract-port","version":"v1","encoding":"json","value":"Zm9v"}"#;
232 assert_eq!(to_string(&packet).unwrap(), expected);
233 }
234}