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

Restructure modules to align with ibc-go's structure #1459

Merged
merged 13 commits into from
Oct 27, 2021
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Restructure the layout of the `ibc` crate to match `ibc-go`'s [layout][ibc-go-layout] ([#1436][issue-1436]).

[issue-1436]: https://github.com/informalsystems/ibc-rs/issues/1436
[ibc-go-layout]: https://github.com/cosmos/ibc-go#contents
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ __pycache__/
.modelator
mc.log

# Ignore OSX .DS_Store files
# Ignore OSX .DS_Store file
.DS_Store
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ics04_channel::context::{ChannelKeeper, ChannelReader};
use crate::core::ics04_channel::context::{ChannelKeeper, ChannelReader};

/// Captures all the dependencies which the ICS20 module requires to be able to dispatch and
/// process IBC messages.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ics04_channel::error as channel_error;
use crate::ics24_host::error::ValidationError;
use crate::ics24_host::identifier::{ChannelId, PortId};
use crate::core::ics04_channel::error as channel_error;
use crate::core::ics24_host::error::ValidationError;
use crate::core::ics24_host::identifier::{ChannelId, PortId};
use crate::prelude::*;
use flex_error::define_error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ use tendermint_proto::Protobuf;

use ibc_proto::ibc::apps::transfer::v1::MsgTransfer as RawMsgTransfer;

use crate::application::ics20_fungible_token_transfer::error::Error;
use crate::ics02_client::height::Height;
use crate::ics24_host::identifier::{ChannelId, PortId};
use crate::applications::ics20_fungible_token_transfer::error::Error;
use crate::core::ics02_client::height::Height;
use crate::core::ics24_host::identifier::{ChannelId, PortId};
use crate::signer::Signer;
use crate::timestamp::Timestamp;
use crate::tx_msg::Msg;

pub const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";

///
/// Message definition for the "packet receiving" datagram.
///
#[derive(Clone, Debug, PartialEq)]
pub struct MsgTransfer {
/// the port on which the packet will be sent
Expand Down Expand Up @@ -105,7 +103,7 @@ pub mod test_util {
use std::time::Duration;

use crate::{
ics24_host::identifier::{ChannelId, PortId},
core::ics24_host::identifier::{ChannelId, PortId},
test_utils::get_dummy_account_id,
timestamp::Timestamp,
Height,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::application::ics20_fungible_token_transfer::context::Ics20Context;
use crate::application::ics20_fungible_token_transfer::error::Error;
use crate::application::ics20_fungible_token_transfer::msgs::transfer::MsgTransfer;
use crate::applications::ics20_fungible_token_transfer::context::Ics20Context;
use crate::applications::ics20_fungible_token_transfer::error::Error;
use crate::applications::ics20_fungible_token_transfer::msgs::transfer::MsgTransfer;
use crate::core::ics04_channel::handler::send_packet::send_packet;
use crate::core::ics04_channel::packet::Packet;
use crate::core::ics04_channel::packet::PacketResult;
use crate::handler::HandlerOutput;
use crate::ics04_channel::handler::send_packet::send_packet;
use crate::ics04_channel::packet::Packet;
use crate::ics04_channel::packet::PacketResult;
use crate::prelude::*;

pub(crate) fn send_transfer<Ctx>(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ use tendermint::Time;
use tendermint_light_client::components::verifier::{ProdVerifier, Verdict, Verifier};
use tendermint_light_client::types::{TrustedBlockState, UntrustedBlockState};

use crate::ics02_client::client_consensus::AnyConsensusState;
use crate::ics02_client::client_def::ClientDef;
use crate::ics02_client::client_state::AnyClientState;
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::context::ClientReader;
use crate::ics02_client::error::Error as Ics02Error;
use crate::ics03_connection::connection::ConnectionEnd;
use crate::ics04_channel::channel::ChannelEnd;
use crate::ics04_channel::packet::Sequence;
use crate::ics07_tendermint::client_state::ClientState;
use crate::ics07_tendermint::consensus_state::ConsensusState;
use crate::ics07_tendermint::error::Error;
use crate::ics07_tendermint::header::Header;
use crate::clients::ics07_tendermint::client_state::ClientState;
use crate::clients::ics07_tendermint::consensus_state::ConsensusState;
use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header;
use crate::core::ics02_client::client_consensus::AnyConsensusState;
use crate::core::ics02_client::client_def::ClientDef;
use crate::core::ics02_client::client_state::AnyClientState;
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::context::ClientReader;
use crate::core::ics02_client::error::Error as Ics02Error;
use crate::core::ics03_connection::connection::ConnectionEnd;
use crate::core::ics04_channel::channel::ChannelEnd;
use crate::core::ics04_channel::packet::Sequence;

use crate::ics23_commitment::commitment::{CommitmentPrefix, CommitmentProofBytes, CommitmentRoot};
use crate::ics24_host::identifier::ConnectionId;
use crate::ics24_host::identifier::{ChannelId, ClientId, PortId};
use crate::core::ics23_commitment::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
use crate::core::ics24_host::identifier::ConnectionId;
use crate::core::ics24_host::identifier::{ChannelId, ClientId, PortId};
use crate::prelude::*;
use crate::Height;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use tendermint_proto::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawClientState;

use crate::ics02_client::client_state::AnyClientState;
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::error::Error as Ics02Error;
use crate::ics02_client::trust_threshold::TrustThreshold;
use crate::ics07_tendermint::error::Error;
use crate::ics07_tendermint::header::Header;
use crate::ics23_commitment::specs::ProofSpecs;
use crate::ics24_host::identifier::ChainId;
use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header;
use crate::core::ics02_client::client_state::AnyClientState;
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::error::Error as Ics02Error;
use crate::core::ics02_client::trust_threshold::TrustThreshold;
use crate::core::ics23_commitment::specs::ProofSpecs;
use crate::core::ics24_host::identifier::ChainId;
use crate::timestamp::ZERO_DURATION;
use crate::Height;

Expand Down Expand Up @@ -163,7 +163,7 @@ impl ClientState {
}
}

impl crate::ics02_client::client_state::ClientState for ClientState {
impl crate::core::ics02_client::client_state::ClientState for ClientState {
fn chain_id(&self) -> ChainId {
self.chain_id.clone()
}
Expand Down Expand Up @@ -260,24 +260,25 @@ mod tests {

use tendermint_rpc::endpoint::abci_query::AbciQuery;

use crate::ics02_client::trust_threshold::TrustThreshold;
use crate::ics07_tendermint::client_state::{AllowUpdate, ClientState};
use crate::ics24_host::identifier::ChainId;
use crate::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState};
use crate::core::ics02_client::trust_threshold::TrustThreshold;
use crate::core::ics24_host::identifier::ChainId;
use crate::test::test_serialization_roundtrip;
use crate::timestamp::ZERO_DURATION;
use crate::Height;

#[test]
fn serialization_roundtrip_no_proof() {
let json_data = include_str!("../../tests/support/query/serialization/client_state.json");
let json_data =
include_str!("../../../tests/support/query/serialization/client_state.json");
println!("json_data: {:?}", json_data);
test_serialization_roundtrip::<AbciQuery>(json_data);
}

#[test]
fn serialization_roundtrip_with_proof() {
let json_data =
include_str!("../../tests/support/query/serialization/client_state_proof.json");
include_str!("../../../tests/support/query/serialization/client_state_proof.json");
println!("json_data: {:?}", json_data);
test_serialization_roundtrip::<AbciQuery>(json_data);
}
Expand Down Expand Up @@ -396,10 +397,10 @@ pub mod test_util {

use tendermint::block::Header;

use crate::ics02_client::client_state::AnyClientState;
use crate::ics02_client::height::Height;
use crate::ics07_tendermint::client_state::{AllowUpdate, ClientState};
use crate::ics24_host::identifier::ChainId;
use crate::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState};
use crate::core::ics02_client::client_state::AnyClientState;
use crate::core::ics02_client::height::Height;
use crate::core::ics24_host::identifier::ChainId;

pub fn get_dummy_tendermint_client_state(tm_header: Header) -> AnyClientState {
AnyClientState::Tendermint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use tendermint_proto::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;

use crate::ics02_client::client_consensus::AnyConsensusState;
use crate::ics02_client::client_type::ClientType;
use crate::ics07_tendermint::error::Error;
use crate::ics07_tendermint::header::Header;
use crate::ics23_commitment::commitment::CommitmentRoot;
use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header;
use crate::core::ics02_client::client_consensus::AnyConsensusState;
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics23_commitment::commitment::CommitmentRoot;

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct ConsensusState {
Expand All @@ -31,7 +31,7 @@ impl ConsensusState {
}
}

impl crate::ics02_client::client_consensus::ConsensusState for ConsensusState {
impl crate::core::ics02_client::client_consensus::ConsensusState for ConsensusState {
type Error = Infallible;

fn client_type(&self) -> ClientType {
Expand Down Expand Up @@ -122,15 +122,15 @@ mod tests {
#[test]
fn serialization_roundtrip_no_proof() {
let json_data =
include_str!("../../tests/support/query/serialization/consensus_state.json");
include_str!("../../../tests/support/query/serialization/consensus_state.json");
println!("json_data: {:?}", json_data);
test_serialization_roundtrip::<AbciQuery>(json_data);
}

#[test]
fn serialization_roundtrip_with_proof() {
let json_data =
include_str!("../../tests/support/query/serialization/consensus_state_proof.json");
include_str!("../../../tests/support/query/serialization/consensus_state_proof.json");
println!("json_data: {:?}", json_data);
test_serialization_roundtrip::<AbciQuery>(json_data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::prelude::*;

use flex_error::{define_error, TraceError};

use crate::ics24_host::error::ValidationError;
use crate::core::ics24_host::error::ValidationError;
use crate::Height;
use tendermint::account::Id;
use tendermint::hash::Hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use crate::timestamp::Timestamp;

use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader;

use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::header::AnyHeader;
use crate::ics07_tendermint::error::Error;
use crate::ics24_host::identifier::ChainId;
use crate::clients::ics07_tendermint::error::Error;
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::header::AnyHeader;
use crate::core::ics24_host::identifier::ChainId;
use crate::Height;
use core::cmp::Ordering;

Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn headers_compatible(header: &SignedHeader, other: &SignedHeader) -> bool {
}
}

impl crate::ics02_client::header::Header for Header {
impl crate::core::ics02_client::header::Header for Header {
fn client_type(&self) -> ClientType {
ClientType::Tendermint
}
Expand Down Expand Up @@ -156,13 +156,15 @@ pub mod test_util {
use tendermint::validator::Set as ValidatorSet;
use tendermint::PublicKey;

use crate::ics07_tendermint::header::Header;
use crate::clients::ics07_tendermint::header::Header;
use crate::Height;

pub fn get_dummy_tendermint_header() -> tendermint::block::Header {
serde_json::from_str::<SignedHeader>(include_str!("../../tests/support/signed_header.json"))
.unwrap()
.header
serde_json::from_str::<SignedHeader>(include_str!(
"../../../tests/support/signed_header.json"
))
.unwrap()
.header
}

// TODO: This should be replaced with a ::default() or ::produce().
Expand All @@ -182,7 +184,7 @@ pub mod test_util {
pub fn get_dummy_ics07_header() -> Header {
// Build a SignedHeader from a JSON file.
let shdr = serde_json::from_str::<SignedHeader>(include_str!(
"../../tests/support/signed_header.json"
"../../../tests/support/signed_header.json"
))
.unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use tendermint_proto::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour;

use crate::ics02_client::misbehaviour::AnyMisbehaviour;
use crate::ics07_tendermint::error::Error;
use crate::ics07_tendermint::header::Header;
use crate::ics24_host::identifier::ClientId;
use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header;
use crate::core::ics02_client::misbehaviour::AnyMisbehaviour;
use crate::core::ics24_host::identifier::ClientId;
use crate::Height;

#[derive(Clone, Debug, PartialEq)]
Expand All @@ -17,7 +17,7 @@ pub struct Misbehaviour {
pub header2: Header,
}

impl crate::ics02_client::misbehaviour::Misbehaviour for Misbehaviour {
impl crate::core::ics02_client::misbehaviour::Misbehaviour for Misbehaviour {
fn client_id(&self) -> &ClientId {
&self.client_id
}
Expand Down
1 change: 1 addition & 0 deletions modules/src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod ics07_tendermint;
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use prost_types::Any;
use serde::Serialize;
use tendermint_proto::Protobuf;

use crate::clients::ics07_tendermint::consensus_state;
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::error::Error;
use crate::core::ics02_client::height::Height;
use crate::core::ics23_commitment::commitment::CommitmentRoot;
use crate::core::ics24_host::identifier::ClientId;
use crate::events::WithBlockDataType;
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::error::Error;
use crate::ics02_client::height::Height;
use crate::ics07_tendermint::consensus_state;
use crate::ics23_commitment::commitment::CommitmentRoot;
use crate::ics24_host::identifier::ClientId;
use crate::timestamp::Timestamp;

#[cfg(any(test, feature = "mocks"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use ibc_proto::ibc::core::commitment::v1::MerkleProof;

use crate::clients::ics07_tendermint::client_def::TendermintClient;
use crate::core::ics02_client::client_consensus::{AnyConsensusState, ConsensusState};
use crate::core::ics02_client::client_state::{AnyClientState, ClientState};
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::context::ClientReader;
use crate::core::ics02_client::error::Error;
use crate::core::ics02_client::header::{AnyHeader, Header};
use crate::core::ics03_connection::connection::ConnectionEnd;
use crate::core::ics04_channel::channel::ChannelEnd;
use crate::core::ics04_channel::packet::Sequence;
use crate::core::ics23_commitment::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId};
use crate::downcast;
use crate::ics02_client::client_consensus::{AnyConsensusState, ConsensusState};
use crate::ics02_client::client_state::{AnyClientState, ClientState};
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::context::ClientReader;
use crate::ics02_client::error::Error;
use crate::ics02_client::header::{AnyHeader, Header};
use crate::ics03_connection::connection::ConnectionEnd;
use crate::ics04_channel::channel::ChannelEnd;
use crate::ics04_channel::packet::Sequence;
use crate::ics07_tendermint::client_def::TendermintClient;
use crate::ics23_commitment::commitment::{CommitmentPrefix, CommitmentProofBytes, CommitmentRoot};
use crate::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId};
use crate::prelude::*;
use crate::Height;

Expand Down
Loading