Skip to content

Commit

Permalink
Add parity-scale-codec and borsh for IbcEvent (#321)
Browse files Browse the repository at this point in the history
* add parity-scale-codec and borsh for IbcEvent

* Create 320-add-borsh-and-scale-codec-for-ibcevent.md

* Update no-std-check ibc-proto dep

* Add patch ibc-proto for no-std-check

* Update ibc-proto patch

* Update Cargo.toml

* Update ibc-proto version and Add serde feature

Signed-off-by: Davirain <davirain.yin@gmail.com>
  • Loading branch information
DaviRain-Su authored Jan 11, 2023
1 parent 59dd3d9 commit 4b29332
Show file tree
Hide file tree
Showing 12 changed files with 633 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add parity-scale-codec and borsh for ibc::events::IbcEvent
([#320](https://github.com/cosmos/ibc-rs/issues/320))
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ members = [

exclude = [
"ci/no-std-check",
]
]
4 changes: 2 additions & 2 deletions ci/no-std-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resolver = "2"

[dependencies]
ibc = { path = "../../crates/ibc", default-features = false, features = ["mocks-no-std"] }
ibc-proto = { version = "0.24.0", default-features = false }
ibc-proto = { version = "0.24.1", default-features = false, features = ["parity-scale-codec", "borsh"]}
tendermint = { version = "0.28.0", default-features = false }
tendermint-proto = { version = "0.28.0", default-features = false }
tendermint-light-client-verifier = { version = "0.28.0", default-features = false }
Expand All @@ -29,4 +29,4 @@ substrate-std = [
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
]
3 changes: 2 additions & 1 deletion crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ val_exec_ctx = []
# Depends on the `testgen` suite for generating Tendermint light blocks.
mocks = ["tendermint-testgen", "tendermint/clock", "cfg-if", "parking_lot"]
mocks-no-std = ["cfg-if"]
serde = []

[dependencies]
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
ibc-proto = { version = "0.24.0", default-features = false }
ibc-proto = { version = "0.24.1", default-features = false, features = ["parity-scale-codec", "borsh"] }
ics23 = { version = "0.9.0", default-features = false, features = ["host-functions"] }
time = { version = ">=0.3.0, <0.3.18", default-features = false }
serde_derive = { version = "1.0.104", default-features = false }
Expand Down
135 changes: 126 additions & 9 deletions crates/ibc/src/core/ics02_client/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ pub const CONSENSUS_HEIGHTS_ATTRIBUTE_KEY: &str = "consensus_heights";
/// The content of the `key` field for the header in update client event.
pub const HEADER_ATTRIBUTE_KEY: &str = "header";

#[derive(Debug, From)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, From, PartialEq, Eq)]
struct ClientIdAttribute {
client_id: ClientId,
}
Expand All @@ -36,7 +49,20 @@ impl From<ClientIdAttribute> for abci::EventAttribute {
}
}

#[derive(Debug, From)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, From, PartialEq, Eq)]
struct ClientTypeAttribute {
client_type: ClientType,
}
Expand All @@ -47,7 +73,20 @@ impl From<ClientTypeAttribute> for abci::EventAttribute {
}
}

#[derive(Debug, From)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, From, PartialEq, Eq)]
struct ConsensusHeightAttribute {
consensus_height: Height,
}
Expand All @@ -58,7 +97,20 @@ impl From<ConsensusHeightAttribute> for abci::EventAttribute {
}
}

#[derive(Debug, From)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, From, PartialEq, Eq)]
struct ConsensusHeightsAttribute {
consensus_heights: Vec<Height>,
}
Expand All @@ -74,7 +126,20 @@ impl From<ConsensusHeightsAttribute> for abci::EventAttribute {
}
}

#[derive(Debug, From)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, From, PartialEq, Eq)]
struct HeaderAttribute {
header: Any,
}
Expand All @@ -90,7 +155,20 @@ impl From<HeaderAttribute> for abci::EventAttribute {
}

/// CreateClient event signals the creation of a new on-chain client (IBC client).
#[derive(Debug)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CreateClient {
client_id: ClientIdAttribute,
client_type: ClientTypeAttribute,
Expand Down Expand Up @@ -133,7 +211,20 @@ impl From<CreateClient> for abci::Event {
}

/// UpdateClient event signals a recent update of an on-chain client (IBC Client).
#[derive(Debug)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UpdateClient {
client_id: ClientIdAttribute,
client_type: ClientTypeAttribute,
Expand Down Expand Up @@ -199,7 +290,20 @@ impl From<UpdateClient> for abci::Event {

/// ClientMisbehaviour event signals the update of an on-chain client (IBC Client) with evidence of
/// misbehaviour.
#[derive(Debug)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClientMisbehaviour {
client_id: ClientIdAttribute,
client_type: ClientTypeAttribute,
Expand Down Expand Up @@ -232,7 +336,20 @@ impl From<ClientMisbehaviour> for abci::Event {
}

/// Signals a recent upgrade of an on-chain client (IBC Client).
#[derive(Debug)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UpgradeClient {
client_id: ClientIdAttribute,
client_type: ClientTypeAttribute,
Expand Down
77 changes: 70 additions & 7 deletions crates/ibc/src/core/ics03_connection/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Types for the IBC events emitted from Tendermint Websocket by the connection module.

use serde_derive::{Deserialize, Serialize};
use tendermint::abci;

use crate::core::ics24_host::identifier::{ClientId, ConnectionId};
Expand All @@ -13,7 +12,20 @@ pub const CLIENT_ID_ATTRIBUTE_KEY: &str = "client_id";
pub const COUNTERPARTY_CONN_ID_ATTRIBUTE_KEY: &str = "counterparty_connection_id";
pub const COUNTERPARTY_CLIENT_ID_ATTRIBUTE_KEY: &str = "counterparty_client_id";

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct Attributes {
pub connection_id: ConnectionId,
pub client_id: ClientId,
Expand Down Expand Up @@ -51,7 +63,20 @@ impl From<Attributes> for Vec<abci::EventAttribute> {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenInit(Attributes);

impl OpenInit {
Expand Down Expand Up @@ -92,7 +117,20 @@ impl From<OpenInit> for abci::Event {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenTry(Attributes);

impl OpenTry {
Expand Down Expand Up @@ -133,8 +171,20 @@ impl From<OpenTry> for abci::Event {
}
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenAck(Attributes);

impl OpenAck {
Expand Down Expand Up @@ -176,7 +226,20 @@ impl From<OpenAck> for abci::Event {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenConfirm(Attributes);

impl OpenConfirm {
Expand Down
Loading

0 comments on commit 4b29332

Please sign in to comment.