|
| 1 | +use schemars::JsonSchema; |
| 2 | +use serde::{Deserialize, Serialize}; |
| 3 | + |
| 4 | +use crate::{Binary, Timestamp}; |
| 5 | + |
| 6 | +/// Payload value should be encoded in a format defined by the channel version, |
| 7 | +/// and the module on the other side should know how to parse this. |
| 8 | +#[non_exhaustive] |
| 9 | +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] |
| 10 | +#[serde(rename_all = "snake_case")] |
| 11 | +pub struct EurekaPayload { |
| 12 | + /// The port id on the chain where the packet is sent to (external chain). |
| 13 | + pub destination_port: String, |
| 14 | + /// Version of the receiving contract. |
| 15 | + pub version: String, |
| 16 | + /// Encoding used to serialize the [EurekaPayload::value]. |
| 17 | + pub encoding: String, |
| 18 | + /// Encoded payload data. |
| 19 | + pub value: Binary, |
| 20 | +} |
| 21 | + |
| 22 | +/// These are messages in the IBC lifecycle using the new Eureka approach. Only usable by IBC-enabled contracts |
| 23 | +#[non_exhaustive] |
| 24 | +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] |
| 25 | +#[serde(rename_all = "snake_case")] |
| 26 | +pub enum EurekaMsg { |
| 27 | + /// Sends an IBC packet with given payloads over the existing channel. |
| 28 | + SendPacket { |
| 29 | + /// existing channel to send the tokens over |
| 30 | + channel_id: String, |
| 31 | + timeout: Timestamp, |
| 32 | + payloads: Vec<EurekaPayload>, |
| 33 | + }, |
| 34 | +} |
| 35 | + |
| 36 | +#[cfg(test)] |
| 37 | +mod tests { |
| 38 | + use serde_json::to_string; |
| 39 | + |
| 40 | + use crate::EurekaPayload; |
| 41 | + |
| 42 | + #[test] |
| 43 | + fn eureka_payload_serialize() { |
| 44 | + let packet = EurekaPayload { |
| 45 | + destination_port: "receiving-contract-port".to_string(), |
| 46 | + version: "v1".to_string(), |
| 47 | + encoding: "json".to_string(), |
| 48 | + value: b"foo".into(), |
| 49 | + }; |
| 50 | + let expected = r#"{"destination_port":"receiving-contract-port","version":"v1","encoding":"json","value":"Zm9v"}"#; |
| 51 | + assert_eq!(to_string(&packet).unwrap(), expected); |
| 52 | + } |
| 53 | +} |
0 commit comments