Skip to content

Commit

Permalink
imp: re-export ibc proto types from ibc-proto-rs (#899)
Browse files Browse the repository at this point in the history
* imp: re-export ibc proto types from ibc-proto-rs

* nit: better docstring

* fix: re-export relavant types

* nit

* fix: cargo doc

* fix: expose AnySchema
  • Loading branch information
Farhad-Shabani authored Oct 6, 2023
1 parent a4a5f78 commit a2d10f1
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Re-export ibc proto types from `ibc-proto-rs`` for dependency convenience
([/#898](https://github.com/cosmos/ibc-rs/issues/898))
2 changes: 1 addition & 1 deletion crates/ibc-query/src/core/channel/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! `I` must be a type where writes from one thread are readable from another.
//! This means using `Arc<Mutex<_>>` or `Arc<RwLock<_>>` in most cases.
use std::boxed::Box;
use alloc::boxed::Box;

use ibc::core::ValidationContext;
use ibc::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc-query/src/core/client/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! `I` must be a type where writes from one thread are readable from another.
//! This means using `Arc<Mutex<_>>` or `Arc<RwLock<_>>` in most cases.
use std::boxed::Box;
use alloc::boxed::Box;

use ibc::core::ValidationContext;
use ibc::hosts::tendermint::upgrade_proposal::UpgradeValidationContext;
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc-query/src/core/connection/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! `I` must be a type where writes from one thread are readable from another.
//! This means using `Arc<Mutex<_>>` or `Arc<RwLock<_>>` in most cases.
use std::boxed::Box;
use alloc::boxed::Box;

use ibc::core::ValidationContext;
use ibc::prelude::*;
Expand Down
8 changes: 2 additions & 6 deletions crates/ibc-query/src/core/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Required traits for blanket implementations of [`gRPC query services`](crate::services::core).
//! Required traits for blanket implementations of [`gRPC query services`](crate::core).
use ibc::core::ics03_connection::connection::IdentifiedConnectionEnd;
use ibc::core::ics04_channel::channel::IdentifiedChannelEnd;
Expand All @@ -9,18 +9,14 @@ use ibc::core::{ContextError, ValidationContext};
use ibc::prelude::*;
use ibc::Height;

/// Context to be implemented by the host to provide proofs in gRPC query responses
///
/// Trait used for the [`gRPC query services`](crate::services).
/// Context to be implemented by the host to provide proofs in query responses
pub trait ProvableContext {
/// Returns the proof for the given path at the given height.
/// As this is in the context of IBC, the path is expected to be an [`IbcPath`](Path).
fn get_proof(&self, height: Height, path: &Path) -> Option<Vec<u8>>;
}

/// Context to be implemented by the host that provides gRPC query services.
///
/// Trait used for the [`gRPC query services`](crate::services).
pub trait QueryContext: ProvableContext + ValidationContext {
// Client queries

Expand Down
2 changes: 2 additions & 0 deletions crates/ibc-query/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::string::{String, ToString};

use displaydoc::Display;
use ibc::core::ics02_client::error::ClientError;
use ibc::core::ics24_host::identifier::IdentifierError;
Expand Down
21 changes: 17 additions & 4 deletions crates/ibc-query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//!
//! The provided structs includes blanket implementation of their corresponding gRPC service traits,
//! if the host implements the following _context_ traits.
//! - [`ValidationContext`](crate::core::ValidationContext)
//! - [`ProvableContext`](crate::services::core::context::ProvableContext)
//! - [`QueryContext`](crate::services::core::context::QueryContext)
//! - [`UpgradeValidationContext`](crate::hosts::tendermint::upgrade_proposal::UpgradeValidationContext)
//! - [`ValidationContext`](ibc::core::ValidationContext)
//! - [`ProvableContext`](crate::core::context::ProvableContext)
//! - [`QueryContext`](crate::core::context::QueryContext)
//! - [`UpgradeValidationContext`](ibc::hosts::tendermint::upgrade_proposal::UpgradeValidationContext)
//! - Only for [`ClientQuery::upgraded_client_state`](ibc_proto::ibc::core::client::v1::query_server::Query::upgraded_client_state) and [`ClientQuery::upgraded_client_state`](ibc_proto::ibc::core::client::v1::query_server::Query::upgraded_consensus_state)
//!
//! Example
Expand Down Expand Up @@ -43,6 +43,19 @@
//! .add_service(channel_service)
//! .serve(addr);
//! ```
//!
#![cfg_attr(not(test), deny(clippy::unwrap_used))]
#![no_std]
#![deny(
warnings,
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
unused_qualifications,
rust_2018_idioms
)]
#![forbid(unsafe_code)]

extern crate alloc;

Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics04_channel/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TryFrom<Vec<u8>> for Acknowledgement {
}

/// Defines a convenience type for IBC applications to construct an
/// [`Acknowledgement`](super::acknowledgement::Acknowledgement) based on the
/// [`Acknowledgement`] based on the
/// success or failure of processing a received packet.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
Expand All @@ -69,7 +69,7 @@ pub enum AcknowledgementStatus {
}

/// A wrapper type that guards variants of
/// [`AcknowledgementStatus`](crate::core::ics04_channel::acknowledgement::AcknowledgementStatus)
/// [`AcknowledgementStatus`]
/// against being constructed with an empty value.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
12 changes: 9 additions & 3 deletions crates/ibc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ pub mod test_utils; // Context mock, the underlying host chain, and client types

pub mod prelude;
mod signer;
mod utils;
pub mod utils;

#[cfg(feature = "serde")]
mod serializers;

/// Re-export the `Any` type which used across the library.
pub use ibc_proto::google::protobuf::Any;
/// Re-exports pertinent ibc proto types from the `ibc-proto-rs` crate for added convenience
pub mod proto {
pub use ibc_proto::google::protobuf::Any;
pub use ibc_proto::ibc::apps::transfer;
pub use ibc_proto::ibc::core;
pub use ibc_proto::ibc::lightclients::tendermint;
pub use ibc_proto::protobuf;
}
6 changes: 3 additions & 3 deletions crates/ibc/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Various utilities used internally
pub mod macros;
pub mod pretty;
pub(crate) mod schema;
pub(crate) mod macros;
pub(crate) mod pretty;
pub mod schema;
1 change: 0 additions & 1 deletion crates/ibc/src/utils/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::prelude::*;

/// Dummy type that mirrors `ibc_proto::google::protobuf::Any`.
/// Meant to be used with `#[cfg_attr(feature = "schema", schemars(with = "crate::utils::schema::AnySchema"))]`
#[allow(dead_code)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct AnySchema {
pub type_url: String,
Expand Down

0 comments on commit a2d10f1

Please sign in to comment.