1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::{Addr, Binary, IbcAcknowledgement, Timestamp};
5
6#[non_exhaustive]
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub struct Ibc2Payload {
12 pub source_port: String,
14 pub destination_port: String,
16 pub version: String,
18 pub encoding: String,
20 pub value: Binary,
22}
23
24impl Ibc2Payload {
25 pub fn new(
26 source_port: String,
27 destination_port: String,
28 version: String,
29 encoding: String,
30 value: Binary,
31 ) -> Self {
32 Self {
33 source_port,
34 destination_port,
35 version,
36 encoding,
37 value,
38 }
39 }
40}
41
42#[non_exhaustive]
45#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
46#[serde(rename_all = "snake_case")]
47pub enum Ibc2Msg {
48 SendPacket {
50 source_client: String,
51 timeout: Timestamp,
52 payloads: Vec<Ibc2Payload>,
53 },
54 WriteAcknowledgement {
57 source_client: String,
59 packet_sequence: u64,
61 ack: IbcAcknowledgement,
63 },
64}
65
66#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
70#[non_exhaustive]
71pub struct Ibc2PacketReceiveMsg {
72 pub payload: Ibc2Payload,
74 pub relayer: Addr,
76 pub source_client: String,
78 pub packet_sequence: u64,
80}
81
82impl Ibc2PacketReceiveMsg {
83 pub fn new(
84 payload: Ibc2Payload,
85 relayer: Addr,
86 source_client: String,
87 packet_sequence: u64,
88 ) -> Self {
89 Self {
90 payload,
91 relayer,
92 source_client,
93 packet_sequence,
94 }
95 }
96}
97
98#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
103#[non_exhaustive]
104pub struct Ibc2PacketTimeoutMsg {
105 pub payload: Ibc2Payload,
107 pub source_client: String,
109 pub destination_client: String,
111 pub packet_sequence: u64,
113 pub relayer: Addr,
115}
116
117impl Ibc2PacketTimeoutMsg {
118 pub fn new(
119 payload: Ibc2Payload,
120 source_client: String,
121 destination_client: String,
122 packet_sequence: u64,
123 relayer: Addr,
124 ) -> Self {
125 Self {
126 payload,
127 source_client,
128 destination_client,
129 packet_sequence,
130 relayer,
131 }
132 }
133}
134
135#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
137#[non_exhaustive]
138pub struct Ibc2PacketAckMsg {
139 pub source_client: String,
140 pub destination_client: String,
141 pub data: Ibc2Payload,
142 pub acknowledgement: Binary,
143 pub relayer: Addr,
144}
145
146impl Ibc2PacketAckMsg {
147 pub fn new(
148 source_client: String,
149 destination_client: String,
150 data: Ibc2Payload,
151 acknowledgement: Binary,
152 relayer: Addr,
153 ) -> Self {
154 Self {
155 source_client,
156 destination_client,
157 data,
158 acknowledgement,
159 relayer,
160 }
161 }
162}
163
164#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
172#[non_exhaustive]
173pub struct Ibc2PacketSendMsg {
174 pub payload: Ibc2Payload,
176 pub source_client: String,
178 pub destination_client: String,
180 pub packet_sequence: u64,
182 pub signer: Addr,
184}
185
186impl Ibc2PacketSendMsg {
187 pub fn new(
188 payload: Ibc2Payload,
189 source_client: String,
190 destination_client: String,
191 packet_sequence: u64,
192 signer: Addr,
193 ) -> Self {
194 Self {
195 payload,
196 source_client,
197 destination_client,
198 packet_sequence,
199 signer,
200 }
201 }
202}
203
204#[cfg(test)]
205mod tests {
206 use serde_json::to_string;
207
208 use crate::Ibc2Payload;
209
210 #[test]
211 fn ibc2_payload_serialize() {
212 let packet = Ibc2Payload {
213 source_port: "sending-contractr-port".to_string(),
214 destination_port: "receiving-contract-port".to_string(),
215 version: "v1".to_string(),
216 encoding: "json".to_string(),
217 value: b"foo".into(),
218 };
219 let expected = r#"{"source_port":"sending-contractr-port","destination_port":"receiving-contract-port","version":"v1","encoding":"json","value":"Zm9v"}"#;
220 assert_eq!(to_string(&packet).unwrap(), expected);
221 }
222}