From 357f51d2d175524d0e3e6afd487e51e9c8569cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Laferri=C3=A8re?= Date: Tue, 5 Sep 2023 11:43:30 -0400 Subject: [PATCH] Implement `JsonSchema` for `MsgEnvelope` (#856) * derive JsonSchema * fmt * changelog --- .../improvements/856-jsonschema-derive-msgenvelope.md | 2 ++ crates/ibc/src/core/ics02_client/msgs.rs | 3 ++- crates/ibc/src/core/ics02_client/msgs/create_client.rs | 3 +++ crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs | 2 ++ crates/ibc/src/core/ics02_client/msgs/update_client.rs | 2 ++ .../ibc/src/core/ics02_client/msgs/upgrade_client.rs | 3 +++ crates/ibc/src/core/ics03_connection/connection.rs | 1 + crates/ibc/src/core/ics03_connection/msgs.rs | 2 ++ .../src/core/ics03_connection/msgs/conn_open_ack.rs | 2 ++ .../core/ics03_connection/msgs/conn_open_confirm.rs | 1 + .../src/core/ics03_connection/msgs/conn_open_init.rs | 1 + .../src/core/ics03_connection/msgs/conn_open_try.rs | 2 ++ crates/ibc/src/core/ics03_connection/version.rs | 1 + crates/ibc/src/core/ics04_channel/acknowledgement.rs | 1 + crates/ibc/src/core/ics04_channel/channel.rs | 1 + crates/ibc/src/core/ics04_channel/msgs.rs | 4 ++++ .../ibc/src/core/ics04_channel/msgs/acknowledgement.rs | 1 + .../src/core/ics04_channel/msgs/chan_close_confirm.rs | 1 + .../ibc/src/core/ics04_channel/msgs/chan_close_init.rs | 1 + .../ibc/src/core/ics04_channel/msgs/chan_open_ack.rs | 1 + .../src/core/ics04_channel/msgs/chan_open_confirm.rs | 1 + .../ibc/src/core/ics04_channel/msgs/chan_open_init.rs | 1 + .../ibc/src/core/ics04_channel/msgs/chan_open_try.rs | 1 + crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs | 1 + crates/ibc/src/core/ics04_channel/msgs/timeout.rs | 1 + .../src/core/ics04_channel/msgs/timeout_on_close.rs | 1 + crates/ibc/src/core/ics04_channel/packet.rs | 2 ++ crates/ibc/src/core/ics04_channel/version.rs | 1 + crates/ibc/src/core/ics23_commitment/commitment.rs | 2 ++ crates/ibc/src/core/ics24_host/identifier.rs | 1 + crates/ibc/src/core/msgs.rs | 1 + crates/ibc/src/core/timestamp.rs | 3 +++ crates/ibc/src/utils/mod.rs | 1 + crates/ibc/src/utils/schema.rs | 10 ++++++++++ 34 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .changelog/unreleased/improvements/856-jsonschema-derive-msgenvelope.md create mode 100644 crates/ibc/src/utils/schema.rs diff --git a/.changelog/unreleased/improvements/856-jsonschema-derive-msgenvelope.md b/.changelog/unreleased/improvements/856-jsonschema-derive-msgenvelope.md new file mode 100644 index 000000000..5eac84360 --- /dev/null +++ b/.changelog/unreleased/improvements/856-jsonschema-derive-msgenvelope.md @@ -0,0 +1,2 @@ +- Add `JsonSchema` derive for `MsgEnvelope` + ([#856](https://github.com/cosmos/ibc-rs/pull/856)) diff --git a/crates/ibc/src/core/ics02_client/msgs.rs b/crates/ibc/src/core/ics02_client/msgs.rs index b1b29ac82..221adbe3c 100644 --- a/crates/ibc/src/core/ics02_client/msgs.rs +++ b/crates/ibc/src/core/ics02_client/msgs.rs @@ -1,5 +1,4 @@ //! Defines the client message types that are sent to the chain by the relayer. - use ibc_proto::google::protobuf::Any; use crate::core::ics02_client::msgs::create_client::MsgCreateClient; @@ -7,6 +6,7 @@ use crate::core::ics02_client::msgs::misbehaviour::MsgSubmitMisbehaviour; use crate::core::ics02_client::msgs::update_client::MsgUpdateClient; use crate::core::ics02_client::msgs::upgrade_client::MsgUpgradeClient; use crate::core::ics24_host::identifier::ClientId; +use crate::prelude::*; use crate::signer::Signer; pub mod create_client; @@ -20,6 +20,7 @@ pub mod upgrade_client; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub enum ClientMsg { CreateClient(MsgCreateClient), diff --git a/crates/ibc/src/core/ics02_client/msgs/create_client.rs b/crates/ibc/src/core/ics02_client/msgs/create_client.rs index 93cbc126f..37214c326 100644 --- a/crates/ibc/src/core/ics02_client/msgs/create_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/create_client.rs @@ -16,9 +16,12 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgCreateClient"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgCreateClient { + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub client_state: Any, + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub consensus_state: Any, pub signer: Signer, } diff --git a/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs b/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs index 02fe61905..d2a885b46 100644 --- a/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs +++ b/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs @@ -17,11 +17,13 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgSubmitMisbehaviour"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgSubmitMisbehaviour { /// client unique identifier pub client_id: ClientId, /// misbehaviour used for freezing the light client + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub misbehaviour: ProtoAny, /// signer address pub signer: Signer, diff --git a/crates/ibc/src/core/ics02_client/msgs/update_client.rs b/crates/ibc/src/core/ics02_client/msgs/update_client.rs index 36ef02b36..4d4b809c5 100644 --- a/crates/ibc/src/core/ics02_client/msgs/update_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/update_client.rs @@ -20,9 +20,11 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgUpdateClient"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgUpdateClient { pub client_id: ClientId, + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub client_message: Any, pub signer: Signer, } diff --git a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs index 55da7a238..6fdbca40e 100644 --- a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs @@ -21,14 +21,17 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgUpgradeClient"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgUpgradeClient { // client unique identifier pub client_id: ClientId, // Upgraded client state + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub upgraded_client_state: Any, // Upgraded consensus state, only contains enough information // to serve as a basis of trust in update logic + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub upgraded_consensus_state: Any, // proof that old chain committed to new client pub proof_upgrade_client: CommitmentProofBytes, diff --git a/crates/ibc/src/core/ics03_connection/connection.rs b/crates/ibc/src/core/ics03_connection/connection.rs index bfb73b645..d3017b406 100644 --- a/crates/ibc/src/core/ics03_connection/connection.rs +++ b/crates/ibc/src/core/ics03_connection/connection.rs @@ -377,6 +377,7 @@ impl ConnectionEnd { derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct Counterparty { client_id: ClientId, diff --git a/crates/ibc/src/core/ics03_connection/msgs.rs b/crates/ibc/src/core/ics03_connection/msgs.rs index 4adae4c9b..04b3da330 100644 --- a/crates/ibc/src/core/ics03_connection/msgs.rs +++ b/crates/ibc/src/core/ics03_connection/msgs.rs @@ -16,6 +16,7 @@ use crate::core::ics03_connection::msgs::conn_open_ack::MsgConnectionOpenAck; use crate::core::ics03_connection::msgs::conn_open_confirm::MsgConnectionOpenConfirm; use crate::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; use crate::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; +use crate::prelude::*; pub mod conn_open_ack; pub mod conn_open_confirm; @@ -27,6 +28,7 @@ pub mod conn_open_try; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub enum ConnectionMsg { OpenInit(MsgConnectionOpenInit), diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs index 415cd3983..a470c8c10 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs @@ -19,6 +19,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenAck" feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgConnectionOpenAck { /// ConnectionId that chain A has chosen for it's ConnectionEnd @@ -26,6 +27,7 @@ pub struct MsgConnectionOpenAck { /// ConnectionId that chain B has chosen for it's ConnectionEnd pub conn_id_on_b: ConnectionId, /// ClientState of client tracking chain A on chain B + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub client_state_of_a_on_b: Any, /// proof of ConnectionEnd stored on Chain B during ConnOpenTry pub proof_conn_end_on_b: CommitmentProofBytes, diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs index cb1528dc3..4e55f5d9e 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs @@ -17,6 +17,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenConf feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgConnectionOpenConfirm { /// ConnectionId that chain B has chosen for it's ConnectionEnd diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs index 322f28cc2..b05a7feec 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs @@ -16,6 +16,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenInit /// Per our convention, this message is sent to chain A. /// The handler will check proofs of chain B. #[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct MsgConnectionOpenInit { /// ClientId on chain A that the connection is being opened for pub client_id_on_a: ClientId, diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs index 64269f075..ba24309f1 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs @@ -19,11 +19,13 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenTry" /// Per our convention, this message is sent to chain B. /// The handler will check proofs of chain A. +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgConnectionOpenTry { /// ClientId on B that the connection is being opened for pub client_id_on_b: ClientId, /// ClientState of client tracking chain B on chain A + #[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))] pub client_state_of_b_on_a: Any, /// ClientId, ConnectionId and prefix of chain A pub counterparty: Counterparty, diff --git a/crates/ibc/src/core/ics03_connection/version.rs b/crates/ibc/src/core/ics03_connection/version.rs index dcdb2b9f8..2eb4d0152 100644 --- a/crates/ibc/src/core/ics03_connection/version.rs +++ b/crates/ibc/src/core/ics03_connection/version.rs @@ -24,6 +24,7 @@ use crate::utils::pretty::PrettySlice; derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Version { /// unique version identifier diff --git a/crates/ibc/src/core/ics04_channel/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/acknowledgement.rs index 4c5d08cd7..a8c07066f 100644 --- a/crates/ibc/src/core/ics04_channel/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/acknowledgement.rs @@ -23,6 +23,7 @@ use crate::prelude::*; derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq, Into)] pub struct Acknowledgement(Vec); diff --git a/crates/ibc/src/core/ics04_channel/channel.rs b/crates/ibc/src/core/ics04_channel/channel.rs index 7cfac5265..56bdaed6a 100644 --- a/crates/ibc/src/core/ics04_channel/channel.rs +++ b/crates/ibc/src/core/ics04_channel/channel.rs @@ -434,6 +434,7 @@ impl From for RawCounterparty { derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Order { None = 0isize, diff --git a/crates/ibc/src/core/ics04_channel/msgs.rs b/crates/ibc/src/core/ics04_channel/msgs.rs index a5e87c6e5..3757f2c5f 100644 --- a/crates/ibc/src/core/ics04_channel/msgs.rs +++ b/crates/ibc/src/core/ics04_channel/msgs.rs @@ -1,6 +1,8 @@ //! Message definitions for all ICS4 domain types: channel open & close handshake datagrams, as well //! as packets. +use crate::prelude::*; + pub(crate) mod acknowledgement; pub(crate) mod chan_close_confirm; pub(crate) mod chan_close_init; @@ -33,6 +35,7 @@ use crate::core::ics24_host::identifier::PortId; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub enum ChannelMsg { OpenInit(MsgChannelOpenInit), @@ -48,6 +51,7 @@ pub enum ChannelMsg { feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub enum PacketMsg { Recv(MsgRecvPacket), diff --git a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs index 250c33921..630a9468e 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs @@ -19,6 +19,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgAcknowledgement"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgAcknowledgement { pub packet: Packet, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs index ed03904f6..b3462ad72 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs @@ -20,6 +20,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseConfirm"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelCloseConfirm { pub port_id_on_b: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs index 4ad83ef81..88dbcd7bc 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs @@ -17,6 +17,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseInit"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelCloseInit { pub port_id_on_a: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs index 56dc166e4..1d0676f58 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs @@ -19,6 +19,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenAck"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenAck { pub port_id_on_a: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs index a0daea61d..bb1714209 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs @@ -20,6 +20,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenConfirm"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenConfirm { pub port_id_on_b: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs index f2c081252..63831cf05 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs @@ -21,6 +21,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenInit"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenInit { pub port_id_on_a: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs index 6e2876332..db8da599c 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs @@ -23,6 +23,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenTry"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenTry { pub port_id_on_b: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs index 9b342a7d1..42a96d559 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs @@ -18,6 +18,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgRecvPacket"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgRecvPacket { /// The packet to be received diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs index b2244b268..286efbda4 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs @@ -19,6 +19,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgTimeout"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgTimeout { pub packet: Packet, diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs index 6e965edc4..7cfb8b075 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs @@ -18,6 +18,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgTimeoutOnClose"; feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgTimeoutOnClose { pub packet: Packet, diff --git a/crates/ibc/src/core/ics04_channel/packet.rs b/crates/ibc/src/core/ics04_channel/packet.rs index b80069acc..4ae6ea5e7 100644 --- a/crates/ibc/src/core/ics04_channel/packet.rs +++ b/crates/ibc/src/core/ics04_channel/packet.rs @@ -66,6 +66,7 @@ impl core::fmt::Display for PacketMsgType { derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] /// The sequence number of a packet enforces ordering among packets from the same source. #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Sequence(u64); @@ -127,6 +128,7 @@ impl core::fmt::Display for Sequence { derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Default, Hash, PartialEq, Eq)] pub struct Packet { pub seq_on_a: Sequence, diff --git a/crates/ibc/src/core/ics04_channel/version.rs b/crates/ibc/src/core/ics04_channel/version.rs index 84feb5e7e..9e07bfe21 100644 --- a/crates/ibc/src/core/ics04_channel/version.rs +++ b/crates/ibc/src/core/ics04_channel/version.rs @@ -27,6 +27,7 @@ use crate::prelude::*; derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct Version(String); diff --git a/crates/ibc/src/core/ics23_commitment/commitment.rs b/crates/ibc/src/core/ics23_commitment/commitment.rs index 1b8af341e..46c4d8150 100644 --- a/crates/ibc/src/core/ics23_commitment/commitment.rs +++ b/crates/ibc/src/core/ics23_commitment/commitment.rs @@ -68,6 +68,7 @@ impl From> for CommitmentRoot { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, PartialEq, Eq)] pub struct CommitmentProofBytes { #[cfg_attr( @@ -150,6 +151,7 @@ impl TryFrom for RawMerkleProof { derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, PartialEq, Eq, Hash, Default)] pub struct CommitmentPrefix { bytes: Vec, diff --git a/crates/ibc/src/core/ics24_host/identifier.rs b/crates/ibc/src/core/ics24_host/identifier.rs index d669d8731..ae5a4fbb2 100644 --- a/crates/ibc/src/core/ics24_host/identifier.rs +++ b/crates/ibc/src/core/ics24_host/identifier.rs @@ -182,6 +182,7 @@ fn parse_chain_id_string(chain_id_str: &str) -> Result<(&str, u64), IdentifierEr derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Into)] pub struct ClientId(String); diff --git a/crates/ibc/src/core/msgs.rs b/crates/ibc/src/core/msgs.rs index 7f8fe8a53..bc3642d29 100644 --- a/crates/ibc/src/core/msgs.rs +++ b/crates/ibc/src/core/msgs.rs @@ -39,6 +39,7 @@ pub trait Msg: Clone { feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub enum MsgEnvelope { Client(ClientMsg), diff --git a/crates/ibc/src/core/timestamp.rs b/crates/ibc/src/core/timestamp.rs index 64add0694..e7b22780d 100644 --- a/crates/ibc/src/core/timestamp.rs +++ b/crates/ibc/src/core/timestamp.rs @@ -23,8 +23,11 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0); /// represented as a `u64` Unix timestamp in nanoseconds, with 0 representing the absence /// of timestamp. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(PartialEq, Eq, Copy, Clone, Debug, Default, PartialOrd, Ord)] pub struct Timestamp { + // Note: The schema representation is the timestamp in nanoseconds (as we do with borsh). + #[cfg_attr(feature = "schema", schemars(with = "u64"))] time: Option