Skip to content

Commit

Permalink
imp: organize imports using rustfmt.toml (#849)
Browse files Browse the repository at this point in the history
* imp: organize imports using rustfmt.toml

* fix: use nightly toolchain for fmt

* fix: add fmt component

* nix: add reorder_imports
  • Loading branch information
Farhad-Shabani authored Sep 5, 2023
1 parent 2d610b6 commit dc8e416
Show file tree
Hide file tree
Showing 124 changed files with 658 additions and 828 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/848-configure-cargo-fmt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Organize imports grouping and granularity using `rustfmt.toml`
([#848](https://github.com/cosmos/ibc-rs/issues/848))
3 changes: 2 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly # Since fmt uses unstable features for organizing imports
components: rustfmt
override: true
- uses: actions-rs/cargo@v1
with:
Expand Down
8 changes: 3 additions & 5 deletions crates/ibc-derive/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use darling::FromDeriveInput;
use proc_macro2::TokenStream;
use quote::quote;
use syn::DeriveInput;

use traits::{
client_state_common::impl_ClientStateCommon, client_state_execution::impl_ClientStateExecution,
client_state_validation::impl_ClientStateValidation,
};
use traits::client_state_common::impl_ClientStateCommon;
use traits::client_state_execution::impl_ClientStateExecution;
use traits::client_state_validation::impl_ClientStateValidation;

#[derive(FromDeriveInput)]
#[darling(attributes(generics))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::{
punctuated::{Iter, Punctuated},
token::Comma,
Variant,
};
use syn::punctuated::{Iter, Punctuated};
use syn::token::Comma;
use syn::Variant;

use crate::utils::{get_enum_variant_type_path, Imports};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::{
punctuated::{Iter, Punctuated},
token::Comma,
Variant,
};
use syn::punctuated::{Iter, Punctuated};
use syn::token::Comma;
use syn::Variant;

use crate::{
client_state::Opts,
utils::{get_enum_variant_type_path, Imports},
};
use crate::client_state::Opts;
use crate::utils::{get_enum_variant_type_path, Imports};

pub(crate) fn impl_ClientStateExecution(
client_state_enum_name: &Ident,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::{
punctuated::{Iter, Punctuated},
token::Comma,
Variant,
};
use syn::punctuated::{Iter, Punctuated};
use syn::token::Comma;
use syn::Variant;

use crate::{
client_state::Opts,
utils::{get_enum_variant_type_path, Imports},
};
use crate::client_state::Opts;
use crate::utils::{get_enum_variant_type_path, Imports};

pub(crate) fn impl_ClientStateValidation(
client_state_enum_name: &Ident,
Expand Down
3 changes: 2 additions & 1 deletion crates/ibc-derive/src/consensus_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::{punctuated::Iter, DeriveInput, Ident, Variant};
use syn::punctuated::Iter;
use syn::{DeriveInput, Ident, Variant};

use crate::utils::{get_enum_variant_type_path, Imports};

Expand Down
13 changes: 8 additions & 5 deletions crates/ibc/src/applications/transfer/amount.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//! Contains the `Amount` type, which represents amounts of tokens transferred.
use crate::prelude::*;
use core::{ops::Deref, str::FromStr};
use derive_more::{Display, From, Into};
use core::ops::Deref;
use core::str::FromStr;

use super::error::TokenTransferError;
use derive_more::{Display, From, Into};
use primitive_types::U256;

use super::error::TokenTransferError;
#[cfg(feature = "schema")]
use crate::alloc::borrow::ToOwned;
#[cfg(feature = "schema")]
use crate::alloc::{borrow::ToOwned, string::String};
use crate::alloc::string::String;
use crate::prelude::*;

/// A type for representing token transfer amounts.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
1 change: 1 addition & 0 deletions crates/ibc/src/applications/transfer/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use core::fmt::{Display, Error as FmtError, Formatter};
use core::str::{from_utf8, FromStr};

use ibc_proto::cosmos::base::v1beta1::Coin as ProtoCoin;
use safe_regex::regex;

Expand Down
12 changes: 5 additions & 7 deletions crates/ibc/src/applications/transfer/context.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
//! Defines the main context traits and IBC module callbacks
use crate::prelude::*;

use sha2::{Digest, Sha256};

use super::ack_success_b64;
use super::error::TokenTransferError;
use crate::applications::transfer::events::{AckEvent, AckStatusEvent, RecvEvent, TimeoutEvent};
use crate::applications::transfer::packet::PacketData;
use crate::applications::transfer::relay::refund_packet_token_execute;
use crate::applications::transfer::relay::on_recv_packet::process_recv_packet_execute;
use crate::applications::transfer::relay::{
on_recv_packet::process_recv_packet_execute, refund_packet_token_validate,
refund_packet_token_execute, refund_packet_token_validate,
};
use crate::applications::transfer::{PrefixedCoin, PrefixedDenom, VERSION};
use crate::core::ics04_channel::acknowledgement::Acknowledgement;
use crate::core::ics04_channel::acknowledgement::AcknowledgementStatus;
use crate::core::ics04_channel::acknowledgement::{Acknowledgement, AcknowledgementStatus};
use crate::core::ics04_channel::channel::{Counterparty, Order};
use crate::core::ics04_channel::packet::Packet;
use crate::core::ics04_channel::Version;
use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId};
use crate::core::router::ModuleExtras;
use crate::core::ContextError;
use crate::prelude::*;
use crate::signer::Signer;

/// Methods required in token transfer validation, to be implemented by the host
Expand Down Expand Up @@ -414,9 +412,9 @@ pub fn on_timeout_packet_execute(

#[cfg(test)]
pub(crate) mod test {
use super::*;
use subtle_encoding::bech32;

use super::*;
use crate::applications::transfer::context::cosmos_adr028_escrow_address;
use crate::core::ics04_channel::channel::{Counterparty, Order};
use crate::core::ics04_channel::Version;
Expand Down
1 change: 0 additions & 1 deletion crates/ibc/src/applications/transfer/denom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use ibc_proto::ibc::applications::transfer::v1::DenomTrace as RawDenomTrace;
use super::error::TokenTransferError;
use crate::core::ics24_host::identifier::{ChannelId, PortId};
use crate::prelude::*;

#[cfg(feature = "serde")]
use crate::serializers::serde_string;

Expand Down
1 change: 1 addition & 0 deletions crates/ibc/src/applications/transfer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use core::convert::Infallible;
use core::str::Utf8Error;

use displaydoc::Display;
use ibc_proto::protobuf::Error as TendermintProtoError;
use uint::FromDecStrErr;
Expand Down
3 changes: 1 addition & 2 deletions crates/ibc/src/applications/transfer/events.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! Defines all token transfer event types
use super::Memo;
use crate::applications::transfer::{Amount, PrefixedDenom, MODULE_ID_STR};
use crate::core::events::ModuleEvent;
use crate::core::ics04_channel::acknowledgement::AcknowledgementStatus;
use crate::prelude::*;
use crate::signer::Signer;

use super::Memo;

const EVENT_TYPE_PACKET: &str = "fungible_token_packet";
const EVENT_TYPE_TIMEOUT: &str = "timeout";
const EVENT_TYPE_DENOM_TRACE: &str = "denomination_trace";
Expand Down
4 changes: 3 additions & 1 deletion crates/ibc/src/applications/transfer/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
//! with a token transfer
use core::convert::Infallible;
use core::fmt::{self, Display};
use core::fmt::{
Display, {self},
};
use core::str::FromStr;

use crate::prelude::*;
Expand Down
7 changes: 2 additions & 5 deletions crates/ibc/src/applications/transfer/msgs/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Defines the token transfer message type
use crate::prelude::*;

use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer;
use ibc_proto::protobuf::Protobuf;
Expand All @@ -13,6 +11,7 @@ use crate::core::ics04_channel::timeout::TimeoutHeight;
use crate::core::ics24_host::identifier::{ChannelId, PortId};
use crate::core::timestamp::Timestamp;
use crate::core::{ContextError, Msg};
use crate::prelude::*;

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

Expand Down Expand Up @@ -127,12 +126,10 @@ impl TryFrom<Any> for MsgTransfer {

#[cfg(test)]
pub mod test_util {
use super::*;

use core::ops::Add;
use core::time::Duration;

use super::MsgTransfer;
use super::{MsgTransfer, *};
use crate::applications::transfer::packet::PacketData;
use crate::core::ics04_channel::packet::{Packet, Sequence};
use crate::core::ics04_channel::timeout::TimeoutHeight;
Expand Down
8 changes: 4 additions & 4 deletions crates/ibc/src/applications/transfer/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use alloc::string::ToString;
use core::convert::TryFrom;
use core::str::FromStr;

#[cfg(feature = "schema")]
use crate::alloc::borrow::ToOwned;

use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPacketData;

use super::error::TokenTransferError;
use super::{Amount, Memo, PrefixedCoin, PrefixedDenom};
#[cfg(feature = "schema")]
use crate::alloc::borrow::ToOwned;
use crate::signer::Signer;

/// Defines the structure of token transfers' packet bytes
Expand Down Expand Up @@ -67,10 +66,11 @@ impl From<PacketData> for RawPacketData {
#[cfg(test)]
mod tests {

use primitive_types::U256;

use super::*;
use crate::applications::transfer::BaseCoin;
use crate::test_utils::get_dummy_bech32_account;
use primitive_types::U256;

impl PacketData {
pub fn new_dummy() -> Self {
Expand Down
3 changes: 1 addition & 2 deletions crates/ibc/src/applications/transfer/relay.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! Implements the processing logic for ICS20 (token transfer) message.
use super::context::{TokenTransferExecutionContext, TokenTransferValidationContext};
use crate::applications::transfer::error::TokenTransferError;
use crate::applications::transfer::is_sender_chain_source;
use crate::applications::transfer::packet::PacketData;
use crate::core::ics04_channel::packet::Packet;
use crate::prelude::*;

use super::context::{TokenTransferExecutionContext, TokenTransferValidationContext};

pub mod on_recv_packet;
pub mod send_transfer;

Expand Down
38 changes: 18 additions & 20 deletions crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
mod misbehaviour;
mod update_client;

use crate::prelude::*;

use core::cmp::max;
use core::convert::{TryFrom, TryInto};
use core::str::FromStr;
Expand All @@ -17,12 +15,16 @@ use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof;
use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState;
use ibc_proto::protobuf::Protobuf;
use prost::Message;

use tendermint::chain::id::MAX_LENGTH as MaxChainIdLen;
use tendermint::trust_threshold::TrustThresholdFraction as TendermintTrustThresholdFraction;
use tendermint_light_client_verifier::options::Options;
use tendermint_light_client_verifier::ProdVerifier;

use super::trust_threshold::TrustThreshold;
use super::{
client_type as tm_client_type, ExecutionContext as TmExecutionContext,
ValidationContext as TmValidationContext,
};
use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState;
use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header as TmHeader;
Expand All @@ -40,17 +42,13 @@ use crate::core::ics23_commitment::commitment::{
use crate::core::ics23_commitment::merkle::{apply_prefix, MerkleProof};
use crate::core::ics23_commitment::specs::ProofSpecs;
use crate::core::ics24_host::identifier::{ChainId, ClientId};
use crate::core::ics24_host::path::Path;
use crate::core::ics24_host::path::{ClientConsensusStatePath, ClientStatePath, UpgradeClientPath};
use crate::core::ics24_host::path::{
ClientConsensusStatePath, ClientStatePath, Path, UpgradeClientPath,
};
use crate::core::timestamp::ZERO_DURATION;
use crate::prelude::*;
use crate::Height;

use super::trust_threshold::TrustThreshold;
use super::{
client_type as tm_client_type, ExecutionContext as TmExecutionContext,
ValidationContext as TmValidationContext,
};

pub const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState";

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -735,9 +733,10 @@ impl TryFrom<Any> for ClientState {
type Error = ClientError;

fn try_from(raw: Any) -> Result<Self, Self::Error> {
use bytes::Buf;
use core::ops::Deref;

use bytes::Buf;

fn decode_client_state<B: Buf>(buf: B) -> Result<ClientState, Error> {
RawTmClientState::decode(buf)
.map_err(Error::Decode)?
Expand Down Expand Up @@ -783,22 +782,21 @@ fn check_header_trusted_next_validator_set(

#[cfg(test)]
mod tests {
use super::*;

use crate::clients::ics07_tendermint::header::test_util::get_dummy_tendermint_header;
use crate::Height;
use core::time::Duration;
use test_log::test;

use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::core::client::v1::Height as RawHeight;
use ibc_proto::ics23::ProofSpec as Ics23ProofSpec;
use test_log::test;

use super::*;
use crate::clients::ics07_tendermint::client_state::AllowUpdate;
use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::test_util::get_dummy_tendermint_header;
use crate::core::ics23_commitment::specs::ProofSpecs;
use crate::core::ics24_host::identifier::ChainId;
use crate::core::timestamp::ZERO_DURATION;
use crate::Height;

#[derive(Clone, Debug, PartialEq)]
struct ClientStateParams {
Expand Down Expand Up @@ -1120,19 +1118,19 @@ mod serde_tests {

#[cfg(any(test, feature = "mocks"))]
pub mod test_util {
use crate::prelude::*;
use core::str::FromStr;
use core::time::Duration;

use ibc_proto::ibc::core::client::v1::Height as RawHeight;
use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawTmClientState, Fraction};
use tendermint::block::Header;

use crate::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState};
use crate::clients::ics07_tendermint::error::Error;
use crate::core::ics02_client::height::Height;
use crate::core::ics23_commitment::specs::ProofSpecs;
use crate::core::ics24_host::identifier::ChainId;
use ibc_proto::ibc::core::client::v1::Height as RawHeight;
use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawTmClientState, Fraction};
use crate::prelude::*;

impl ClientState {
pub fn new_dummy_from_raw(frozen_height: RawHeight) -> Result<Self, Error> {
Expand Down
Loading

0 comments on commit dc8e416

Please sign in to comment.