Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ibc-types: forward serialization through proto structs #71

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ibc-types-core-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info"]
borsh = ["dep:borsh"]

# This feature is required for token transfer (ICS-20)
with_serde = ["serde", "serde_derive", "serde_json"]
with_serde = ["serde", "serde_derive", "serde_json", "ibc-proto/serde"]

# This feature guards the unfinished implementation of the `UpgradeClient` handler.
upgrade_client = []
Expand Down
21 changes: 16 additions & 5 deletions crates/ibc-types-core-channel/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ use ibc_types_core_connection::ConnectionId;
use crate::{ChannelError, ChannelId, PortId, Version};

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "with_serde",
derive(serde::Serialize, serde::Deserialize),
serde(try_from = "RawIdentifiedChannel", into = "RawIdentifiedChannel")
)]
pub struct IdentifiedChannelEnd {
pub port_id: PortId,
pub channel_id: ChannelId,
Expand Down Expand Up @@ -73,7 +77,11 @@ impl From<IdentifiedChannelEnd> for RawIdentifiedChannel {
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "with_serde",
derive(serde::Serialize, serde::Deserialize),
serde(try_from = "RawChannel", into = "RawChannel")
)]
pub struct ChannelEnd {
pub state: State,
pub ordering: Order,
Expand Down Expand Up @@ -240,7 +248,11 @@ impl ChannelEnd {
}

#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "with_serde",
derive(serde::Serialize, serde::Deserialize),
serde(try_from = "RawCounterparty", into = "RawCounterparty")
)]
pub struct Counterparty {
pub port_id: PortId,
pub channel_id: Option<ChannelId>,
Expand Down Expand Up @@ -323,7 +335,7 @@ impl From<Counterparty> for RawCounterparty {
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Order {
None = 0isize,
Unordered = 1isize,
Expand Down Expand Up @@ -382,7 +394,6 @@ impl FromStr for Order {
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum State {
Uninitialized = 0isize,
Init = 1isize,
Expand Down
18 changes: 9 additions & 9 deletions crates/ibc-types-core-channel/src/events/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ impl SendPacket {
src_channel_id: packet.chan_on_a,
dst_port_id: packet.port_on_b,
dst_channel_id: packet.chan_on_b,
channel_ordering: channel_ordering,
src_connection_id: src_connection_id,
channel_ordering,
src_connection_id,
}
}
}
Expand Down Expand Up @@ -354,8 +354,8 @@ impl ReceivePacket {
src_channel_id: packet.chan_on_a,
dst_port_id: packet.port_on_b,
dst_channel_id: packet.chan_on_b,
channel_ordering: channel_ordering,
dst_connection_id: dst_connection_id,
channel_ordering,
dst_connection_id,
}
}
}
Expand Down Expand Up @@ -559,8 +559,8 @@ impl WriteAcknowledgement {
src_channel_id: packet.chan_on_a,
dst_port_id: packet.port_on_b,
dst_channel_id: packet.chan_on_b,
acknowledgement: acknowledgement,
dst_connection_id: dst_connection_id,
acknowledgement,
dst_connection_id,
}
}
}
Expand Down Expand Up @@ -783,8 +783,8 @@ impl AcknowledgePacket {
src_channel_id: packet.chan_on_a,
dst_port_id: packet.port_on_b,
dst_channel_id: packet.chan_on_b,
channel_ordering: channel_ordering,
src_connection_id: src_connection_id,
channel_ordering,
src_connection_id,
}
}
}
Expand Down Expand Up @@ -948,7 +948,7 @@ impl TimeoutPacket {
src_channel_id: packet.chan_on_a,
dst_port_id: packet.port_on_b,
dst_channel_id: packet.chan_on_b,
channel_ordering: channel_ordering,
channel_ordering,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc-types-core-channel/src/msgs/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl From<MsgAcknowledgement> for RawMsgAcknowledgement {
fn from(domain_msg: MsgAcknowledgement) -> Self {
RawMsgAcknowledgement {
packet: Some(domain_msg.packet.into()),
acknowledgement: domain_msg.acknowledgement.into(),
acknowledgement: domain_msg.acknowledgement,
signer: domain_msg.signer,
proof_height: Some(domain_msg.proof_height_on_b.into()),
proof_acked: domain_msg.proof_acked_on_b.encode_to_vec(),
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc-types-core-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info"]
borsh = ["dep:borsh"]

# This feature is required for token transfer (ICS-20)
with_serde = ["serde", "serde_derive", "serde_json"]
with_serde = ["serde", "serde_derive", "serde_json", "ibc-proto/serde"]

# This feature guards the unfinished implementation of the `UpgradeClient` handler.
upgrade_client = []
Expand All @@ -54,7 +54,7 @@ bytes = { version = "1.2.1", default-features = false }
cfg-if = { version = "1.0.0", optional = true }
derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] }
displaydoc = { version = "0.2", default-features = false }
ibc-proto = { version = "0.37.0", default-features = false, features = ["serde"] }
ibc-proto = { version = "0.37.0", default-features = false }
ibc-types-domain-type = { version = "0.7.0", path = "../ibc-types-domain-type", default-features = false }
ibc-types-identifier = { version = "0.7.0", path = "../ibc-types-identifier", default-features = false }
ibc-types-timestamp = { version = "0.7.0", path = "../ibc-types-timestamp", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc-types-core-client/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Types for ABCI [`Event`](tendermint::abci::Event)s that inform relayers about IBC client events.
//! Types for ABCI [`Event`]s that inform relayers about IBC client events.

use displaydoc::Display;
use subtle_encoding::hex;
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc-types-core-client/src/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::error::Error;
/// An IBC height, containing a revision number (epoch) and a revision height (block height).
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serde",
feature = "with_serde",
derive(serde::Serialize, serde::Deserialize),
serde(try_from = "RawHeight", into = "RawHeight")
)]
Expand Down
4 changes: 1 addition & 3 deletions crates/ibc-types-core-commitment/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub enum Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self {
_ => None,
}
None
}
}
6 changes: 5 additions & 1 deletion crates/ibc-types-core-commitment/src/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use ibc_proto::ibc::core::commitment::v1::MerklePrefix as RawMerklePrefix;
use ibc_types_domain_type::{DomainType, TypeUrl};

#[derive(Clone, Debug, PartialEq, Eq, Default, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "with_serde",
derive(serde::Serialize, serde::Deserialize),
serde(try_from = "RawMerklePrefix", into = "RawMerklePrefix")
)]
pub struct MerklePrefix {
pub key_prefix: Vec<u8>,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc-types-core-commitment/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl MerkleProof {
return Err(anyhow::anyhow!("root hash cannot be empty"));
}
let num = self.proofs.len();
let ics23_specs = Vec::<ics23::ProofSpec>::from(specs.clone());
let ics23_specs = Vec::<ics23::ProofSpec>::from(specs);
if ics23_specs.len() != num {
return Err(anyhow::anyhow!(
"number of specs does not match number of proofs"
Expand Down Expand Up @@ -150,7 +150,7 @@ impl MerkleProof {
return Err(anyhow::anyhow!("root hash cannot be empty"));
}
let num = self.proofs.len();
let ics23_specs = Vec::<ics23::ProofSpec>::from(specs.clone());
let ics23_specs = Vec::<ics23::ProofSpec>::from(specs);
if ics23_specs.len() != num {
return Err(anyhow::anyhow!(
"number of specs does not match number of proofs"
Expand Down
3 changes: 1 addition & 2 deletions crates/ibc-types-core-connection/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Types for ABCI [`Event`](tendermint::abci::Event)s that inform relayers
//! about IBC connection events.
//! Types for ABCI [`Event`]s that inform relayers about IBC client events.

use core::str::FromStr;

Expand Down
2 changes: 1 addition & 1 deletion crates/ibc-types-core-connection/src/msgs/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct MsgConnectionOpenAck {
pub proofs_height_on_b: Height,
/// height of latest header of chain A that updated the client on chain B
pub consensus_height_of_a_on_b: Height,
/// optional proof of the consensus state of the host chain, see: https://github.com/cosmos/ibc/pull/839
/// optional proof of the consensus state of the host chain, see: <https://github.com/cosmos/ibc/pull/839>
host_consensus_state_proof: Option<MerkleProof>,
pub version: Version,
pub signer: String,
Expand Down
6 changes: 5 additions & 1 deletion crates/ibc-types-core-connection/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use crate::ConnectionError;

/// Stores the identifier and the features supported by a version
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "with_serde",
derive(serde::Serialize, serde::Deserialize),
serde(try_from = "RawVersion", into = "RawVersion")
)]
pub struct Version {
/// unique version identifier
pub identifier: String,
Expand Down
12 changes: 8 additions & 4 deletions crates/ibc-types-lightclients-tendermint/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ use crate::{Error, TrustThreshold};
pub const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState";

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "with_serde",
derive(serde::Serialize, serde::Deserialize),
serde(try_from = "RawTmClientState", into = "RawTmClientState")
)]
pub struct ClientState {
pub chain_id: ChainId,
pub trust_level: TrustThreshold,
Expand All @@ -50,7 +54,7 @@ impl DomainType for ClientState {
type Proto = Any;
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AllowUpdate {
pub after_expiry: bool,
Expand Down Expand Up @@ -336,7 +340,7 @@ impl TryFrom<RawTmClientState> for ClientState {
unbonding_period,
max_clock_drift,
latest_height,
raw.proof_specs.into(),
raw.proof_specs,
raw.upgrade_path,
allow_update,
frozen_height,
Expand All @@ -362,7 +366,7 @@ impl From<ClientState> for RawTmClientState {
},
)),
latest_height: Some(value.latest_height.into()),
proof_specs: value.proof_specs.into(),
proof_specs: value.proof_specs,
upgrade_path: value.upgrade_path,
allow_update_after_expiry: value.allow_update.after_expiry,
allow_update_after_misbehaviour: value.allow_update.after_misbehaviour,
Expand Down
6 changes: 3 additions & 3 deletions crates/ibc-types-timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0);
/// a `u64` value and a raw timestamp. In protocol buffer, the timestamp is
/// 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 = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default)]
pub struct Timestamp {
pub time: Option<Time>,
}

// TODO: derive when tendermint::Time supports it:
// https://github.com/informalsystems/tendermint-rs/pull/1054
#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for Timestamp {
fn hash<H: Hasher>(&self, state: &mut H) {
let odt: Option<OffsetDateTime> = self.time.map(Into::into);
Expand All @@ -53,7 +53,7 @@ impl Hash for Timestamp {
///
/// User of this result may want to determine whether error should be raised,
/// when either of the timestamp being compared is invalid.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
pub enum Expiry {
Expired,
Expand Down
Loading