Skip to content

Commit 84ba46a

Browse files
committed
feat: Add EurekaMsg
1 parent 9c7b750 commit 84ba46a

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

packages/std/src/eureka.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

packages/std/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod conversion;
2121
mod deps;
2222
mod encoding;
2323
mod errors;
24+
mod eureka;
2425
mod forward_ref;
2526
mod hex_binary;
2627
mod ibc;
@@ -65,6 +66,7 @@ pub use crate::errors::{
6566
RecoverPubkeyError, RoundDownOverflowError, RoundUpOverflowError, StdError, StdResult,
6667
SystemError, VerificationError,
6768
};
69+
pub use crate::eureka::{EurekaMsg, EurekaPayload};
6870
pub use crate::hex_binary::HexBinary;
6971
pub use crate::ibc::IbcChannelOpenResponse;
7072
pub use crate::ibc::{

0 commit comments

Comments
 (0)