From 9aa70e2795a4c36ec7803876bf2fefd5cd7bb4b9 Mon Sep 17 00:00:00 2001 From: Dariusz Depta Date: Fri, 6 Oct 2023 12:19:24 +0200 Subject: [PATCH] Refactored imports. --- src/app.rs | 9 ++++----- src/bank.rs | 14 ++++++-------- src/contracts.rs | 12 +++++------- src/custom_handler.rs | 8 +++----- src/executor.rs | 6 ++---- src/gov.rs | 3 +-- src/ibc.rs | 3 +-- src/module.rs | 8 +++----- src/prefixed_storage.rs | 7 +++---- src/staking.rs | 15 ++++++--------- src/tests/app.rs | 9 ++++----- src/transactions.rs | 10 ++++------ 12 files changed, 42 insertions(+), 62 deletions(-) diff --git a/src/app.rs b/src/app.rs index a82bd63e..19df5cdc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -9,12 +9,11 @@ use crate::transactions::transactional; use crate::wasm::{ContractData, Wasm, WasmKeeper, WasmSudo}; use crate::AppBuilder; use anyhow::{bail, Result as AnyResult}; +use cosmwasm_std::testing::{MockApi, MockStorage}; use cosmwasm_std::{ - from_slice, - testing::{MockApi, MockStorage}, - to_binary, Addr, Api, Binary, BlockInfo, ContractResult, CosmosMsg, CustomQuery, Empty, GovMsg, - IbcMsg, IbcQuery, Querier, QuerierResult, QuerierWrapper, QueryRequest, Record, Storage, - SystemError, SystemResult, + from_slice, to_binary, Addr, Api, Binary, BlockInfo, ContractResult, CosmosMsg, CustomQuery, + Empty, GovMsg, IbcMsg, IbcQuery, Querier, QuerierResult, QuerierWrapper, QueryRequest, Record, + Storage, SystemError, SystemResult, }; use schemars::JsonSchema; use serde::{de::DeserializeOwned, Serialize}; diff --git a/src/bank.rs b/src/bank.rs index f9c9a96a..40fead14 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -1,18 +1,16 @@ +use crate::app::CosmosRouter; +use crate::executor::AppResponse; +use crate::module::Module; +use crate::prefixed_storage::{prefixed, prefixed_read}; use anyhow::{bail, Result as AnyResult}; -use itertools::Itertools; -use schemars::JsonSchema; - use cosmwasm_std::{ coin, to_binary, Addr, AllBalanceResponse, Api, BalanceResponse, BankMsg, BankQuery, Binary, BlockInfo, Coin, Event, Order, Querier, StdResult, Storage, SupplyResponse, Uint128, }; use cw_storage_plus::Map; use cw_utils::NativeBalance; - -use crate::app::CosmosRouter; -use crate::executor::AppResponse; -use crate::module::Module; -use crate::prefixed_storage::{prefixed, prefixed_read}; +use itertools::Itertools; +use schemars::JsonSchema; const BALANCES: Map<&Addr, NativeBalance> = Map::new("balances"); diff --git a/src/contracts.rs b/src/contracts.rs index e362328b..7ecb1a75 100644 --- a/src/contracts.rs +++ b/src/contracts.rs @@ -1,16 +1,14 @@ +use anyhow::{anyhow, bail, Result as AnyResult}; +use cosmwasm_std::{ + from_slice, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Empty, Env, MessageInfo, + QuerierWrapper, Reply, Response, SubMsg, +}; use schemars::JsonSchema; use serde::de::DeserializeOwned; use std::error::Error; use std::fmt::{self, Debug, Display}; use std::ops::Deref; -use cosmwasm_std::{ - from_slice, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Empty, Env, MessageInfo, - QuerierWrapper, Reply, Response, SubMsg, -}; - -use anyhow::{anyhow, bail, Result as AnyResult}; - /// Interface to call into a `Contract`. pub trait Contract where diff --git a/src/custom_handler.rs b/src/custom_handler.rs index 298f58cc..79163ad4 100644 --- a/src/custom_handler.rs +++ b/src/custom_handler.rs @@ -1,14 +1,12 @@ +use crate::app::CosmosRouter; +use crate::{AppResponse, Module}; use anyhow::{bail, Result as AnyResult}; +use cosmwasm_std::{Addr, Api, Binary, BlockInfo, Empty, Querier, Storage}; use derivative::Derivative; use std::cell::{Ref, RefCell}; use std::ops::Deref; use std::rc::Rc; -use cosmwasm_std::{Addr, Api, Binary, BlockInfo, Empty, Querier, Storage}; - -use crate::app::CosmosRouter; -use crate::{AppResponse, Module}; - /// Internal state of `CachingCustomHandler` wrapping internal mutability so it is not exposed to /// user. Those have to be shared internal state, as after mock is passed to app it is not /// possible to access mock internals which are not exposed by API. diff --git a/src/executor.rs b/src/executor.rs index 75be02d6..3ed7e504 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,13 +1,11 @@ -use std::fmt; - +use anyhow::Result as AnyResult; use cosmwasm_std::{ to_binary, Addr, Attribute, BankMsg, Binary, Coin, CosmosMsg, Event, SubMsgResponse, WasmMsg, }; use cw_utils::{parse_execute_response_data, parse_instantiate_response_data}; use schemars::JsonSchema; use serde::Serialize; - -use anyhow::Result as AnyResult; +use std::fmt; #[derive(Default, Clone, Debug)] pub struct AppResponse { diff --git a/src/gov.rs b/src/gov.rs index 0569cb41..e84d4303 100644 --- a/src/gov.rs +++ b/src/gov.rs @@ -1,6 +1,5 @@ -use cosmwasm_std::{Empty, GovMsg}; - use crate::{FailingModule, Module}; +use cosmwasm_std::{Empty, GovMsg}; pub trait Gov: Module {} diff --git a/src/ibc.rs b/src/ibc.rs index c7bec273..f639640d 100644 --- a/src/ibc.rs +++ b/src/ibc.rs @@ -1,6 +1,5 @@ -use cosmwasm_std::{Binary, Empty, IbcMsg, IbcQuery}; - use crate::{AppResponse, FailingModule, Module}; +use cosmwasm_std::{Binary, Empty, IbcMsg, IbcQuery}; pub trait Ibc: Module {} diff --git a/src/module.rs b/src/module.rs index 08ea1182..3aefa613 100644 --- a/src/module.rs +++ b/src/module.rs @@ -1,12 +1,10 @@ -use std::marker::PhantomData; - -use anyhow::{bail, Result as AnyResult}; -use cosmwasm_std::{Addr, Api, Binary, BlockInfo, CustomQuery, Querier, Storage}; - use crate::app::CosmosRouter; use crate::AppResponse; +use anyhow::{bail, Result as AnyResult}; +use cosmwasm_std::{Addr, Api, Binary, BlockInfo, CustomQuery, Querier, Storage}; use schemars::JsonSchema; use serde::de::DeserializeOwned; +use std::marker::PhantomData; /// Interface of the module. pub trait Module { diff --git a/src/prefixed_storage.rs b/src/prefixed_storage.rs index b74e4d76..0f5e1262 100644 --- a/src/prefixed_storage.rs +++ b/src/prefixed_storage.rs @@ -1,15 +1,14 @@ -mod length_prefixed; -mod namespace_helpers; - use cosmwasm_std::Storage; #[cfg(feature = "iterator")] use cosmwasm_std::{Order, Record}; - use length_prefixed::{to_length_prefixed, to_length_prefixed_nested}; #[cfg(feature = "iterator")] use namespace_helpers::range_with_prefix; use namespace_helpers::{get_with_prefix, remove_with_prefix, set_with_prefix}; +mod length_prefixed; +mod namespace_helpers; + /// An alias of PrefixedStorage::new for less verbose usage pub fn prefixed<'a>(storage: &'a mut dyn Storage, namespace: &[u8]) -> PrefixedStorage<'a> { PrefixedStorage::new(storage, namespace) diff --git a/src/staking.rs b/src/staking.rs index 53a68b1d..2d3be445 100644 --- a/src/staking.rs +++ b/src/staking.rs @@ -1,8 +1,8 @@ -use std::collections::{BTreeSet, VecDeque}; - +use crate::app::CosmosRouter; +use crate::executor::AppResponse; +use crate::prefixed_storage::{prefixed, prefixed_read}; +use crate::{BankSudo, Module}; use anyhow::{anyhow, bail, Result as AnyResult}; -use schemars::JsonSchema; - use cosmwasm_std::{ coin, ensure, ensure_eq, to_binary, Addr, AllDelegationsResponse, AllValidatorsResponse, Api, BankMsg, Binary, BlockInfo, BondedDenomResponse, Coin, CustomQuery, Decimal, Delegation, @@ -10,12 +10,9 @@ use cosmwasm_std::{ StakingQuery, Storage, Timestamp, Uint128, Validator, ValidatorResponse, }; use cw_storage_plus::{Deque, Item, Map}; +use schemars::JsonSchema; use serde::{Deserialize, Serialize}; - -use crate::app::CosmosRouter; -use crate::executor::AppResponse; -use crate::prefixed_storage::{prefixed, prefixed_read}; -use crate::{BankSudo, Module}; +use std::collections::{BTreeSet, VecDeque}; // Contains some general staking parameters #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] diff --git a/src/tests/app.rs b/src/tests/app.rs index c22d0053..e7680a12 100644 --- a/src/tests/app.rs +++ b/src/tests/app.rs @@ -9,12 +9,11 @@ use crate::{ Router, Staking, Wasm, WasmSudo, }; use anyhow::{bail, Result as AnyResult}; -use cosmwasm_std::testing::{mock_env, MockQuerier}; +use cosmwasm_std::testing::{mock_env, MockApi, MockQuerier}; use cosmwasm_std::{ - coin, coins, from_slice, testing::MockApi, to_binary, Addr, AllBalanceResponse, Api, Attribute, - BankMsg, BankQuery, Binary, BlockInfo, Coin, CosmosMsg, CustomQuery, Empty, Event, - OverflowError, OverflowOperation, Querier, Reply, StdError, StdResult, Storage, SubMsg, - WasmMsg, + coin, coins, from_slice, to_binary, Addr, AllBalanceResponse, Api, Attribute, BankMsg, + BankQuery, Binary, BlockInfo, Coin, CosmosMsg, CustomQuery, Empty, Event, OverflowError, + OverflowOperation, Querier, Reply, StdError, StdResult, Storage, SubMsg, WasmMsg, }; use cw_storage_plus::Item; use cw_utils::parse_instantiate_response_data; diff --git a/src/transactions.rs b/src/transactions.rs index 8cfcecd6..834abc46 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -1,3 +1,7 @@ +use anyhow::Result as AnyResult; +use cosmwasm_std::Storage; +#[cfg(feature = "iterator")] +use cosmwasm_std::{Order, Record}; #[cfg(feature = "iterator")] use std::cmp::Ordering; use std::collections::BTreeMap; @@ -8,12 +12,6 @@ use std::iter::Peekable; #[cfg(feature = "iterator")] use std::ops::{Bound, RangeBounds}; -use cosmwasm_std::Storage; -#[cfg(feature = "iterator")] -use cosmwasm_std::{Order, Record}; - -use anyhow::Result as AnyResult; - #[cfg(feature = "iterator")] /// The BTreeMap specific key-value pair reference type, as returned by `BTreeMap, T>::range`. /// This is internal as it can change any time if the map implementation is swapped out.