diff --git a/cli/src/commands/codegen.rs b/cli/src/commands/codegen.rs index a44e13e80c..01cfb6f0fd 100644 --- a/cli/src/commands/codegen.rs +++ b/cli/src/commands/codegen.rs @@ -2,11 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::utils::FileOrUrl; use clap::Parser as ClapParser; use color_eyre::eyre; use subxt_codegen::{DerivesRegistry, TypeSubstitutes, TypeSubstitutionError}; +use crate::utils::FileOrUrl; + /// Generate runtime API client code from metadata. /// /// # Example (with code formatting) diff --git a/cli/src/commands/compatibility.rs b/cli/src/commands/compatibility.rs index 51d50068c8..d9e6e5e3a2 100644 --- a/cli/src/commands/compatibility.rs +++ b/cli/src/commands/compatibility.rs @@ -2,6 +2,8 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::collections::HashMap; + use clap::Parser as ClapParser; use codec::Decode; use color_eyre::eyre::{self, WrapErr}; @@ -10,7 +12,6 @@ use frame_metadata::{ }; use jsonrpsee::client_transport::ws::Uri; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; use subxt_codegen::utils::MetadataVersion; use subxt_metadata::{get_metadata_hash, get_pallet_hash, metadata_v14_to_latest}; diff --git a/cli/src/commands/metadata.rs b/cli/src/commands/metadata.rs index 00537778af..7b146d8fb1 100644 --- a/cli/src/commands/metadata.rs +++ b/cli/src/commands/metadata.rs @@ -2,14 +2,16 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::utils::FileOrUrl; +use std::io::{self, Write}; + use clap::Parser as ClapParser; use codec::{Decode, Encode}; use color_eyre::eyre; use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed}; -use std::io::{self, Write}; use subxt_metadata::{metadata_v14_to_latest, retain_metadata_pallets}; +use crate::utils::FileOrUrl; + /// Download metadata from a substrate node, for use with `subxt` codegen. #[derive(Debug, ClapParser)] pub struct Opts { diff --git a/cli/src/utils.rs b/cli/src/utils.rs index 9a8b6edf82..6bbeaeafeb 100644 --- a/cli/src/utils.rs +++ b/cli/src/utils.rs @@ -2,9 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::{fs, io::Read, path::PathBuf}; + use clap::Args; use color_eyre::eyre; -use std::{fs, io::Read, path::PathBuf}; use subxt_codegen::utils::{MetadataVersion, Uri}; /// The source of the metadata. diff --git a/codegen/src/api/calls.rs b/codegen/src/api/calls.rs index 23b579ed89..795d0b5b48 100644 --- a/codegen/src/api/calls.rs +++ b/codegen/src/api/calls.rs @@ -2,16 +2,17 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use frame_metadata::v15::{PalletMetadata, RuntimeMetadataV15}; +use heck::{ToSnakeCase as _, ToUpperCamelCase as _}; +use proc_macro2::TokenStream as TokenStream2; +use quote::{format_ident, quote}; +use scale_info::form::PortableForm; + use super::CodegenError; use crate::{ types::{CompositeDefFields, TypeGenerator}, CratePath, }; -use frame_metadata::v15::{PalletMetadata, RuntimeMetadataV15}; -use heck::{ToSnakeCase as _, ToUpperCamelCase as _}; -use proc_macro2::TokenStream as TokenStream2; -use quote::{format_ident, quote}; -use scale_info::form::PortableForm; /// Generate calls from the provided pallet's metadata. Each call returns a `StaticTxPayload` /// that can be passed to the subxt client to submit/sign/encode. diff --git a/codegen/src/api/constants.rs b/codegen/src/api/constants.rs index c08745e826..574f74f4ae 100644 --- a/codegen/src/api/constants.rs +++ b/codegen/src/api/constants.rs @@ -2,7 +2,6 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{types::TypeGenerator, CratePath}; use frame_metadata::v15::{PalletMetadata, RuntimeMetadataV15}; use heck::ToSnakeCase as _; use proc_macro2::TokenStream as TokenStream2; @@ -10,6 +9,7 @@ use quote::{format_ident, quote}; use scale_info::form::PortableForm; use super::CodegenError; +use crate::{types::TypeGenerator, CratePath}; /// Generate constants from the provided pallet's metadata. /// diff --git a/codegen/src/api/errors.rs b/codegen/src/api/errors.rs index 0722c8e9a8..a6d027b6c1 100644 --- a/codegen/src/api/errors.rs +++ b/codegen/src/api/errors.rs @@ -7,9 +7,8 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; use scale_info::form::PortableForm; -use crate::types::TypeGenerator; - use super::CodegenError; +use crate::types::TypeGenerator; /// Generate error type alias from the provided pallet metadata. pub fn generate_error_type_alias( diff --git a/codegen/src/api/events.rs b/codegen/src/api/events.rs index 01f46e989d..25955c9695 100644 --- a/codegen/src/api/events.rs +++ b/codegen/src/api/events.rs @@ -2,13 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{types::TypeGenerator, CratePath}; use frame_metadata::v15::PalletMetadata; use proc_macro2::TokenStream as TokenStream2; use quote::quote; use scale_info::form::PortableForm; use super::CodegenError; +use crate::{types::TypeGenerator, CratePath}; /// Generate events from the provided pallet metadata. /// diff --git a/codegen/src/api/mod.rs b/codegen/src/api/mod.rs index 9a0f395e71..2861703f08 100644 --- a/codegen/src/api/mod.rs +++ b/codegen/src/api/mod.rs @@ -11,24 +11,24 @@ mod events; mod runtime_apis; mod storage; -use frame_metadata::v15::RuntimeMetadataV15; +use std::{fs, io::Read, path, string::ToString}; + +use codec::Decode; +use frame_metadata::{v15::RuntimeMetadataV15, RuntimeMetadata, RuntimeMetadataPrefixed}; +use heck::ToSnakeCase as _; +use proc_macro2::TokenStream as TokenStream2; +use quote::{format_ident, quote}; use subxt_metadata::{get_metadata_per_pallet_hash, metadata_v14_to_latest}; +use syn::parse_quote; use super::DerivesRegistry; -use crate::error::CodegenError; use crate::{ + error::CodegenError, ir, types::{CompositeDef, CompositeDefFields, TypeGenerator, TypeSubstitutes}, utils::{fetch_metadata_bytes_blocking, MetadataVersion, Uri}, CratePath, }; -use codec::Decode; -use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed}; -use heck::ToSnakeCase as _; -use proc_macro2::TokenStream as TokenStream2; -use quote::{format_ident, quote}; -use std::{fs, io::Read, path, string::ToString}; -use syn::parse_quote; /// Generates the API for interacting with a Substrate runtime. /// diff --git a/codegen/src/api/runtime_apis.rs b/codegen/src/api/runtime_apis.rs index 3b96ad4397..5292c0f6ba 100644 --- a/codegen/src/api/runtime_apis.rs +++ b/codegen/src/api/runtime_apis.rs @@ -2,15 +2,14 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{types::TypeGenerator, CodegenError, CratePath}; use frame_metadata::v15::{RuntimeApiMetadata, RuntimeMetadataV15}; -use heck::ToSnakeCase as _; -use heck::ToUpperCamelCase as _; - +use heck::{ToSnakeCase as _, ToUpperCamelCase as _}; use proc_macro2::TokenStream as TokenStream2; use quote::{format_ident, quote}; use scale_info::form::PortableForm; +use crate::{types::TypeGenerator, CodegenError, CratePath}; + /// Generates runtime functions for the given API metadata. fn generate_runtime_api( metadata: &RuntimeMetadataV15, diff --git a/codegen/src/api/storage.rs b/codegen/src/api/storage.rs index 058730db43..9dd697a341 100644 --- a/codegen/src/api/storage.rs +++ b/codegen/src/api/storage.rs @@ -2,7 +2,6 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{types::TypeGenerator, CratePath}; use frame_metadata::v15::{ PalletMetadata, RuntimeMetadataV15, StorageEntryMetadata, StorageEntryModifier, StorageEntryType, @@ -13,6 +12,7 @@ use quote::{format_ident, quote}; use scale_info::{form::PortableForm, TypeDef}; use super::CodegenError; +use crate::{types::TypeGenerator, CratePath}; /// Generate functions which create storage addresses from the provided pallet's metadata. /// These addresses can be used to access and iterate over storage values. diff --git a/codegen/src/ir.rs b/codegen/src/ir.rs index 712bc80ba0..51b0031f80 100644 --- a/codegen/src/ir.rs +++ b/codegen/src/ir.rs @@ -2,9 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::error::CodegenError; use syn::token; +use crate::error::CodegenError; + #[derive(Debug, PartialEq, Eq)] pub struct ItemMod { vis: syn::Visibility, diff --git a/codegen/src/types/composite_def.rs b/codegen/src/types/composite_def.rs index 7bffd587ed..853051e950 100644 --- a/codegen/src/types/composite_def.rs +++ b/codegen/src/types/composite_def.rs @@ -2,13 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::error::CodegenError; - -use super::{CratePath, Derives, Field, TypeDefParameters, TypeGenerator, TypeParameter, TypePath}; use proc_macro2::TokenStream; use quote::{format_ident, quote}; use scale_info::{form::PortableForm, Type, TypeDef, TypeDefPrimitive}; +use super::{CratePath, Derives, Field, TypeDefParameters, TypeGenerator, TypeParameter, TypePath}; +use crate::error::CodegenError; + /// Representation of a type which consists of a set of fields. Used to generate Rust code for /// either a standalone `struct` definition, or an `enum` variant. /// diff --git a/codegen/src/types/derives.rs b/codegen/src/types/derives.rs index 8f3c3fa7bb..5f1a063964 100644 --- a/codegen/src/types/derives.rs +++ b/codegen/src/types/derives.rs @@ -2,10 +2,11 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::CratePath; +use std::collections::{HashMap, HashSet}; + use syn::{parse_quote, Path}; -use std::collections::{HashMap, HashSet}; +use crate::CratePath; /// A struct containing the derives that we'll be applying to types; /// a combination of some common derives for all types, plus type diff --git a/codegen/src/types/mod.rs b/codegen/src/types/mod.rs index 4dedb14fc3..566c60038f 100644 --- a/codegen/src/types/mod.rs +++ b/codegen/src/types/mod.rs @@ -11,12 +11,11 @@ mod type_def; mod type_def_params; mod type_path; +use std::collections::BTreeMap; + use proc_macro2::{Ident, Span, TokenStream}; use quote::{quote, ToTokens}; use scale_info::{form::PortableForm, PortableRegistry, Type, TypeDef}; -use std::collections::BTreeMap; - -use crate::error::CodegenError; pub use self::{ composite_def::{CompositeDef, CompositeDefFieldType, CompositeDefFields}, @@ -26,6 +25,7 @@ pub use self::{ type_def_params::TypeDefParameters, type_path::{TypeParameter, TypePath, TypePathType}, }; +use crate::error::CodegenError; pub type Field = scale_info::Field; diff --git a/codegen/src/types/substitutes.rs b/codegen/src/types/substitutes.rs index 683bfe1e9b..532cf2279f 100644 --- a/codegen/src/types/substitutes.rs +++ b/codegen/src/types/substitutes.rs @@ -2,11 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{error::TypeSubstitutionError, CratePath}; use std::{borrow::Borrow, collections::HashMap}; + use syn::{parse_quote, spanned::Spanned as _}; use super::{TypePath, TypePathType}; +use crate::{error::TypeSubstitutionError, CratePath}; /// A map of type substitutes. We match on the paths to generated types in order /// to figure out when to swap said type with some provided substitute. diff --git a/codegen/src/types/tests.rs b/codegen/src/types/tests.rs index e1f4caddc5..dc9ae96477 100644 --- a/codegen/src/types/tests.rs +++ b/codegen/src/types/tests.rs @@ -2,11 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use super::*; use pretty_assertions::assert_eq; use scale_info::{meta_type, scale, Registry, TypeInfo}; use syn::parse_quote; +use super::*; + const MOD_PATH: &[&str] = &["subxt_codegen", "types", "tests"]; fn get_mod<'a>(module: &'a Module, path_segs: &[&'static str]) -> Option<&'a Module> { diff --git a/codegen/src/types/type_def.rs b/codegen/src/types/type_def.rs index 25fa02556a..2bebdc35ee 100644 --- a/codegen/src/types/type_def.rs +++ b/codegen/src/types/type_def.rs @@ -2,16 +2,16 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::error::CodegenError; +use proc_macro2::TokenStream; +use quote::{format_ident, quote}; +use scale_info::{form::PortableForm, Type, TypeDef}; +use syn::parse_quote; use super::{ CompositeDef, CompositeDefFields, CratePath, Derives, TypeDefParameters, TypeGenerator, TypeParameter, }; -use proc_macro2::TokenStream; -use quote::{format_ident, quote}; -use scale_info::{form::PortableForm, Type, TypeDef}; -use syn::parse_quote; +use crate::error::CodegenError; /// Generates a Rust `struct` or `enum` definition based on the supplied [`scale-info::Type`]. /// diff --git a/codegen/src/types/type_def_params.rs b/codegen/src/types/type_def_params.rs index 15dc5b6bc2..6289358123 100644 --- a/codegen/src/types/type_def_params.rs +++ b/codegen/src/types/type_def_params.rs @@ -2,10 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::collections::BTreeSet; + +use quote::quote; + use super::TypeParameter; use crate::types::CompositeDefFieldType; -use quote::quote; -use std::collections::BTreeSet; /// Represents the set of generic type parameters for generating a type definition e.g. the `T` in /// `Foo`. diff --git a/codegen/src/types/type_path.rs b/codegen/src/types/type_path.rs index 18d85aea78..e6c84deeeb 100644 --- a/codegen/src/types/type_path.rs +++ b/codegen/src/types/type_path.rs @@ -2,14 +2,15 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::CratePath; +use std::collections::BTreeSet; use proc_macro2::{Ident, TokenStream}; use quote::format_ident; use scale_info::{form::PortableForm, Path, TypeDefPrimitive}; -use std::collections::BTreeSet; use syn::parse_quote; +use crate::CratePath; + /// An opaque struct representing a type path. The main usage of this is /// to spit out as tokens in some `quote!{ ... }` macro; the inner structure /// should be unimportant. diff --git a/codegen/src/utils/fetch_metadata.rs b/codegen/src/utils/fetch_metadata.rs index 9d49e35ac4..4173afb645 100644 --- a/codegen/src/utils/fetch_metadata.rs +++ b/codegen/src/utils/fetch_metadata.rs @@ -2,7 +2,8 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::error::FetchMetadataError; +use std::time::Duration; + use codec::{Decode, Encode}; use jsonrpsee::{ async_client::ClientBuilder, @@ -11,7 +12,8 @@ use jsonrpsee::{ http_client::HttpClientBuilder, rpc_params, }; -use std::time::Duration; + +use crate::error::FetchMetadataError; /// The metadata version that is fetched from the node. #[derive(Default, Debug, Clone, Copy)] diff --git a/codegen/src/utils/mod.rs b/codegen/src/utils/mod.rs index 3f0e77f71e..624f0ecfea 100644 --- a/codegen/src/utils/mod.rs +++ b/codegen/src/utils/mod.rs @@ -7,9 +7,8 @@ mod fetch_metadata; // easy access to this type needed for fetching metadata: -pub use jsonrpsee::client_transport::ws::Uri; - pub use fetch_metadata::{ fetch_metadata_bytes, fetch_metadata_bytes_blocking, fetch_metadata_hex, fetch_metadata_hex_blocking, MetadataVersion, }; +pub use jsonrpsee::client_transport::ws::Uri; diff --git a/examples/examples/balance_transfer_with_params.rs b/examples/examples/balance_transfer_with_params.rs index c94140d421..eefca1a938 100644 --- a/examples/examples/balance_transfer_with_params.rs +++ b/examples/examples/balance_transfer_with_params.rs @@ -1,6 +1,9 @@ use sp_keyring::AccountKeyring; -use subxt::config::polkadot::{Era, PlainTip, PolkadotExtrinsicParamsBuilder as Params}; -use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig}; +use subxt::{ + config::polkadot::{Era, PlainTip, PolkadotExtrinsicParamsBuilder as Params}, + tx::PairSigner, + OnlineClient, PolkadotConfig, +}; #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")] pub mod polkadot {} diff --git a/examples/examples/block_extrinsics.rs b/examples/examples/block_extrinsics.rs index e71182c421..d6275a16aa 100644 --- a/examples/examples/block_extrinsics.rs +++ b/examples/examples/block_extrinsics.rs @@ -10,9 +10,10 @@ //! polkadot --dev --tmp //! ``` +use std::time::Duration; + use futures::StreamExt; use sp_keyring::AccountKeyring; -use std::time::Duration; use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig}; #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")] diff --git a/examples/examples/runtime_apis_dynamic.rs b/examples/examples/runtime_apis_dynamic.rs index c861c53357..e8e531820d 100644 --- a/examples/examples/runtime_apis_dynamic.rs +++ b/examples/examples/runtime_apis_dynamic.rs @@ -1,6 +1,5 @@ use sp_keyring::AccountKeyring; -use subxt::dynamic::Value; -use subxt::{config::PolkadotConfig, OnlineClient}; +use subxt::{config::PolkadotConfig, dynamic::Value, OnlineClient}; #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")] pub mod polkadot {} diff --git a/examples/examples/runtime_apis_raw.rs b/examples/examples/runtime_apis_raw.rs index fc61ff4b3b..e22fb3a837 100644 --- a/examples/examples/runtime_apis_raw.rs +++ b/examples/examples/runtime_apis_raw.rs @@ -1,6 +1,7 @@ -use subxt::ext::codec::Compact; -use subxt::ext::frame_metadata::RuntimeMetadataPrefixed; -use subxt::{OnlineClient, PolkadotConfig}; +use subxt::{ + ext::{codec::Compact, frame_metadata::RuntimeMetadataPrefixed}, + OnlineClient, PolkadotConfig, +}; #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")] pub mod polkadot {} diff --git a/examples/examples/setup_client_custom_rpc.rs b/examples/examples/setup_client_custom_rpc.rs index ed04f1f4fa..294cf38ba5 100644 --- a/examples/examples/setup_client_custom_rpc.rs +++ b/examples/examples/setup_client_custom_rpc.rs @@ -3,6 +3,7 @@ use std::{ pin::Pin, sync::{Arc, Mutex}, }; + use subxt::{ rpc::{RawValue, RpcClientT, RpcFuture, RpcSubscription}, OnlineClient, PolkadotConfig, diff --git a/examples/examples/setup_client_offline.rs b/examples/examples/setup_client_offline.rs index ba5d9b31ab..07ea008718 100644 --- a/examples/examples/setup_client_offline.rs +++ b/examples/examples/setup_client_offline.rs @@ -1,8 +1,10 @@ -use subxt::ext::codec::Decode; -use subxt::ext::frame_metadata::RuntimeMetadataPrefixed; -use subxt::metadata::Metadata; -use subxt::utils::H256; -use subxt::{config::PolkadotConfig, OfflineClient}; +use subxt::{ + config::PolkadotConfig, + ext::{codec::Decode, frame_metadata::RuntimeMetadataPrefixed}, + metadata::Metadata, + utils::H256, + OfflineClient, +}; #[tokio::main] async fn main() -> Result<(), Box> { diff --git a/examples/examples/storage_fetch_dynamic.rs b/examples/examples/storage_fetch_dynamic.rs index 43325770ea..4697044b66 100644 --- a/examples/examples/storage_fetch_dynamic.rs +++ b/examples/examples/storage_fetch_dynamic.rs @@ -1,6 +1,8 @@ use sp_keyring::AccountKeyring; -use subxt::dynamic::{At, Value}; -use subxt::{OnlineClient, PolkadotConfig}; +use subxt::{ + dynamic::{At, Value}, + OnlineClient, PolkadotConfig, +}; #[tokio::main] async fn main() -> Result<(), Box> { diff --git a/metadata/benches/bench.rs b/metadata/benches/bench.rs index d264fbe5f3..e74838bf47 100644 --- a/metadata/benches/bench.rs +++ b/metadata/benches/bench.rs @@ -2,11 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::{fs, path::Path}; + use codec::Decode; use criterion::*; use frame_metadata::{v15::RuntimeMetadataV15, RuntimeMetadata, RuntimeMetadataPrefixed}; use scale_info::{form::PortableForm, TypeDef, TypeDefVariant}; -use std::{fs, path::Path}; use subxt_metadata::{ get_call_hash, get_constant_hash, get_metadata_hash, get_pallet_hash, get_storage_hash, metadata_v14_to_latest, diff --git a/metadata/src/lib.rs b/metadata/src/lib.rs index 702da037ee..071d043003 100644 --- a/metadata/src/lib.rs +++ b/metadata/src/lib.rs @@ -6,7 +6,6 @@ mod retain; mod validation; use frame_metadata::{v14::RuntimeMetadataV14, v15::RuntimeMetadataV15}; - pub use retain::retain_metadata_pallets; pub use validation::{ get_call_hash, get_constant_hash, get_metadata_hash, get_metadata_per_pallet_hash, diff --git a/metadata/src/retain.rs b/metadata/src/retain.rs index c17d71c140..6bfeb73e8d 100644 --- a/metadata/src/retain.rs +++ b/metadata/src/retain.rs @@ -4,15 +4,16 @@ //! Utility functions to generate a subset of the metadata. -use frame_metadata::v15::{ - ExtrinsicMetadata, PalletMetadata, RuntimeApiMetadata, RuntimeMetadataV15, StorageEntryType, -}; -use scale_info::{form::PortableForm, interner::UntrackedSymbol, TypeDef}; use std::{ any::TypeId, collections::{BTreeMap, HashSet}, }; +use frame_metadata::v15::{ + ExtrinsicMetadata, PalletMetadata, RuntimeApiMetadata, RuntimeMetadataV15, StorageEntryType, +}; +use scale_info::{form::PortableForm, interner::UntrackedSymbol, TypeDef}; + /// Collect all type IDs needed to represent the provided pallet. fn collect_pallet_types(pallet: &PalletMetadata, type_ids: &mut HashSet) { if let Some(storage) = &pallet.storage { @@ -249,11 +250,13 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::metadata_v14_to_latest; + use std::{fs, path::Path}; + use codec::Decode; use frame_metadata::{v15::RuntimeMetadataV15, RuntimeMetadata, RuntimeMetadataPrefixed}; - use std::{fs, path::Path}; + + use super::*; + use crate::metadata_v14_to_latest; fn load_metadata() -> RuntimeMetadataV15 { let bytes = fs::read(Path::new("../artifacts/polkadot_metadata.scale")) diff --git a/metadata/src/validation.rs b/metadata/src/validation.rs index eb0f5c4a82..898af571f3 100644 --- a/metadata/src/validation.rs +++ b/metadata/src/validation.rs @@ -4,12 +4,13 @@ //! Utility functions for metadata validation. +use std::collections::HashSet; + use frame_metadata::v15::{ ExtrinsicMetadata, PalletMetadata, RuntimeApiMetadata, RuntimeApiMethodMetadata, RuntimeMetadataV15, StorageEntryMetadata, StorageEntryType, }; use scale_info::{form::PortableForm, Field, PortableRegistry, TypeDef, Variant}; -use std::collections::HashSet; /// Start with a predefined hashing value for the pallets. const MAGIC_PALLET_VALUE: &[u8] = &[19]; @@ -576,7 +577,6 @@ pub enum NotFound { #[cfg(test)] mod tests { - use super::*; use bitvec::{order::Lsb0, vec::BitVec}; use frame_metadata::v15::{ ExtrinsicMetadata, PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata, @@ -585,6 +585,8 @@ mod tests { }; use scale_info::meta_type; + use super::*; + // Define recursive types. #[allow(dead_code)] #[derive(scale_info::TypeInfo)] diff --git a/subxt/src/blocks/block_types.rs b/subxt/src/blocks/block_types.rs index 37830973ee..2d182aba81 100644 --- a/subxt/src/blocks/block_types.rs +++ b/subxt/src/blocks/block_types.rs @@ -2,6 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::sync::Arc; + +use futures::lock::Mutex as AsyncMutex; + use crate::{ blocks::{extrinsic_types::ExtrinsicPartTypeIds, Extrinsics}, client::{OfflineClientT, OnlineClientT}, @@ -13,9 +17,6 @@ use crate::{ storage::Storage, }; -use futures::lock::Mutex as AsyncMutex; -use std::sync::Arc; - /// A representation of a block. pub struct Block { header: T::Header, diff --git a/subxt/src/blocks/blocks_client.rs b/subxt/src/blocks/blocks_client.rs index 0f535c5caf..f550e12a3f 100644 --- a/subxt/src/blocks/blocks_client.rs +++ b/subxt/src/blocks/blocks_client.rs @@ -2,6 +2,11 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::{future::Future, pin::Pin}; + +use derivative::Derivative; +use futures::{future::Either, stream, Stream, StreamExt}; + use super::Block; use crate::{ client::OnlineClientT, @@ -9,9 +14,6 @@ use crate::{ error::{BlockError, Error}, utils::PhantomDataSendSync, }; -use derivative::Derivative; -use futures::{future::Either, stream, Stream, StreamExt}; -use std::{future::Future, pin::Pin}; type BlockStream = Pin> + Send>>; type BlockStreamRes = Result, Error>; diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index ac090c7092..a7a7cd875d 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -2,6 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::{collections::HashMap, sync::Arc}; + +use codec::Decode; +use derivative::Derivative; +use frame_metadata::v15::RuntimeMetadataV15; +use scale_decode::DecodeAsFields; + use crate::{ blocks::block_types::{get_events, CachedEvents}, client::{OfflineClientT, OnlineClientT}, @@ -13,12 +20,6 @@ use crate::{ Metadata, }; -use codec::Decode; -use derivative::Derivative; -use frame_metadata::v15::RuntimeMetadataV15; -use scale_decode::DecodeAsFields; -use std::{collections::HashMap, sync::Arc}; - /// Trait to uniquely identify the extrinsic's identity from the runtime metadata. /// /// Generated API structures that represent an extrinsic implement this trait. @@ -622,8 +623,6 @@ impl ExtrinsicEvents { #[cfg(test)] mod tests { - use super::*; - use crate::{rpc::types::RuntimeVersion, OfflineClient, PolkadotConfig}; use assert_matches::assert_matches; use codec::{Decode, Encode}; use frame_metadata::{ @@ -634,6 +633,9 @@ mod tests { use scale_info::{meta_type, TypeInfo}; use scale_value::Value; + use super::*; + use crate::{rpc::types::RuntimeVersion, OfflineClient, PolkadotConfig}; + // Extrinsic needs to contain at least the generic type parameter "Call" // for the metadata to be valid. // The "Call" type from the metadata is used to decode extrinsics. diff --git a/subxt/src/client/mod.rs b/subxt/src/client/mod.rs index e2a36f0baf..2b5d9d38bd 100644 --- a/subxt/src/client/mod.rs +++ b/subxt/src/client/mod.rs @@ -12,12 +12,11 @@ mod offline_client; mod online_client; pub use offline_client::{OfflineClient, OfflineClientT}; -pub use online_client::{ - ClientRuntimeUpdater, OnlineClient, OnlineClientT, RuntimeUpdaterStream, Update, UpgradeError, -}; - #[cfg(any( feature = "jsonrpsee-ws", all(feature = "jsonrpsee-web", target_arch = "wasm32") ))] pub use online_client::default_rpc_client; +pub use online_client::{ + ClientRuntimeUpdater, OnlineClient, OnlineClientT, RuntimeUpdaterStream, Update, UpgradeError, +}; diff --git a/subxt/src/client/offline_client.rs b/subxt/src/client/offline_client.rs index 815ca2a071..2109512f7e 100644 --- a/subxt/src/client/offline_client.rs +++ b/subxt/src/client/offline_client.rs @@ -2,13 +2,15 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::sync::Arc; + +use derivative::Derivative; + use crate::{ blocks::BlocksClient, constants::ConstantsClient, events::EventsClient, rpc::types::RuntimeVersion, runtime_api::RuntimeApiClient, storage::StorageClient, tx::TxClient, Config, Metadata, }; -use derivative::Derivative; -use std::sync::Arc; /// A trait representing a client that can perform /// offline-only actions. diff --git a/subxt/src/client/online_client.rs b/subxt/src/client/online_client.rs index 44f68635fc..7861c7512d 100644 --- a/subxt/src/client/online_client.rs +++ b/subxt/src/client/online_client.rs @@ -2,6 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::sync::Arc; + +use derivative::Derivative; +use futures::future; +use parking_lot::RwLock; + use super::{OfflineClient, OfflineClientT}; use crate::{ blocks::BlocksClient, @@ -17,10 +23,6 @@ use crate::{ tx::TxClient, Config, Metadata, }; -use derivative::Derivative; -use futures::future; -use parking_lot::RwLock; -use std::sync::Arc; /// A trait representing a client that can perform /// online actions. diff --git a/subxt/src/config/extrinsic_params.rs b/subxt/src/config/extrinsic_params.rs index 6fa9a508f9..0b8377a13d 100644 --- a/subxt/src/config/extrinsic_params.rs +++ b/subxt/src/config/extrinsic_params.rs @@ -7,12 +7,14 @@ //! implementation of the trait is provided ([`BaseExtrinsicParams`]) which is //! used by the provided Substrate and Polkadot configuration. -use crate::{utils::Encoded, Config}; -use codec::{Compact, Decode, Encode}; use core::fmt::Debug; + +use codec::{Compact, Decode, Encode}; use derivative::Derivative; use serde::{Deserialize, Serialize}; +use crate::{utils::Encoded, Config}; + /// This trait allows you to configure the "signed extra" and /// "additional" parameters that are signed and used in transactions. /// see [`BaseExtrinsicParams`] for an implementation that is compatible with diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index b776689c3c..2bad6d732d 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -12,12 +12,12 @@ pub mod extrinsic_params; pub mod polkadot; pub mod substrate; -use codec::{Decode, Encode}; use core::fmt::Debug; -use serde::{de::DeserializeOwned, Serialize}; +use codec::{Decode, Encode}; pub use extrinsic_params::ExtrinsicParams; pub use polkadot::PolkadotConfig; +use serde::{de::DeserializeOwned, Serialize}; pub use substrate::SubstrateConfig; /// Runtime types. @@ -115,9 +115,10 @@ impl> Config /// implement subxt's Hasher and Header traits for some substrate structs #[cfg(feature = "substrate-compat")] mod substrate_impls { - use super::*; use primitive_types::{H256, U256}; + use super::*; + impl Header for sp_runtime::generic::Header where Self: Encode, diff --git a/subxt/src/config/polkadot.rs b/subxt/src/config/polkadot.rs index de46f05b44..211108af96 100644 --- a/subxt/src/config/polkadot.rs +++ b/subxt/src/config/polkadot.rs @@ -4,15 +4,15 @@ //! Polkadot specific configuration +use codec::Encode; +pub use primitive_types::{H256, U256}; + use super::{ extrinsic_params::{BaseExtrinsicParams, BaseExtrinsicParamsBuilder}, Config, }; -use codec::Encode; - pub use crate::utils::{AccountId32, MultiAddress, MultiSignature}; use crate::SubstrateConfig; -pub use primitive_types::{H256, U256}; /// Default set of commonly used types by Polkadot nodes. pub enum PolkadotConfig {} diff --git a/subxt/src/config/substrate.rs b/subxt/src/config/substrate.rs index 3bf97b52db..018b1cc7d3 100644 --- a/subxt/src/config/substrate.rs +++ b/subxt/src/config/substrate.rs @@ -4,15 +4,15 @@ //! Substrate specific configuration +use codec::{Decode, Encode}; +pub use primitive_types::{H256, U256}; +use serde::{Deserialize, Serialize}; + use super::{ extrinsic_params::{BaseExtrinsicParams, BaseExtrinsicParamsBuilder}, Config, Hasher, Header, }; -use codec::{Decode, Encode}; -use serde::{Deserialize, Serialize}; - pub use crate::utils::{AccountId32, MultiAddress, MultiSignature}; -pub use primitive_types::{H256, U256}; /// Default set of commonly used types by Substrate runtimes. // Note: We only use this at the type level, so it should be impossible to diff --git a/subxt/src/constants/constant_address.rs b/subxt/src/constants/constant_address.rs index e70daab492..6bd9e92443 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -2,9 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{dynamic::DecodedValueThunk, metadata::DecodeWithMetadata}; use std::borrow::Cow; +use crate::{dynamic::DecodedValueThunk, metadata::DecodeWithMetadata}; + /// This represents a constant address. Anything implementing this trait /// can be used to fetch constants. pub trait ConstantAddress { diff --git a/subxt/src/constants/constants_client.rs b/subxt/src/constants/constants_client.rs index e81a25b9dc..d6f0ff904a 100644 --- a/subxt/src/constants/constants_client.rs +++ b/subxt/src/constants/constants_client.rs @@ -2,6 +2,8 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use derivative::Derivative; + use super::ConstantAddress; use crate::{ client::OfflineClientT, @@ -9,7 +11,6 @@ use crate::{ metadata::{DecodeWithMetadata, MetadataError}, Config, }; -use derivative::Derivative; /// A client for accessing constants. #[derive(Derivative)] diff --git a/subxt/src/dynamic.rs b/subxt/src/dynamic.rs index ec318da4c9..c599c1ec0a 100644 --- a/subxt/src/dynamic.rs +++ b/subxt/src/dynamic.rs @@ -5,13 +5,13 @@ //! This module provides the entry points to create dynamic //! transactions, storage and constant lookups. +use scale_decode::DecodeAsType; +pub use scale_value::{At, Value}; + use crate::{ error::Error, metadata::{DecodeWithMetadata, Metadata}, }; -use scale_decode::DecodeAsType; - -pub use scale_value::{At, Value}; /// A [`scale_value::Value`] type endowed with contextual information /// regarding what type was used to decode each part of it. This implements @@ -20,16 +20,13 @@ pub use scale_value::{At, Value}; pub type DecodedValue = scale_value::Value; // Submit dynamic transactions. -pub use crate::tx::dynamic as tx; - // Lookup constants dynamically. pub use crate::constants::dynamic as constant; - -// Lookup storage values dynamically. -pub use crate::storage::{dynamic as storage, dynamic_root as storage_root}; - // Execute runtime API function call dynamically. pub use crate::runtime_api::dynamic as runtime_api_call; +// Lookup storage values dynamically. +pub use crate::storage::{dynamic as storage, dynamic_root as storage_root}; +pub use crate::tx::dynamic as tx; /// This is the result of making a dynamic request to a node. From this, /// we can return the raw SCALE bytes that we were handed back, or we can diff --git a/subxt/src/error/dispatch_error.rs b/subxt/src/error/dispatch_error.rs index aa730b0bc6..a0ea67f7ea 100644 --- a/subxt/src/error/dispatch_error.rs +++ b/subxt/src/error/dispatch_error.rs @@ -5,13 +5,16 @@ //! A representation of the dispatch error; an error returned when //! something fails in trying to submit/execute a transaction. -use crate::metadata::{DecodeWithMetadata, Metadata}; use core::fmt::Debug; -use scale_decode::visitor::DecodeAsTypeResult; use std::borrow::Cow; +use scale_decode::visitor::DecodeAsTypeResult; + use super::Error; -use crate::error::RootError; +use crate::{ + error::RootError, + metadata::{DecodeWithMetadata, Metadata}, +}; /// An error dispatching a transaction. #[derive(Debug, thiserror::Error, PartialEq, Eq)] diff --git a/subxt/src/error/mod.rs b/subxt/src/error/mod.rs index 96fb6dfad2..c12946c086 100644 --- a/subxt/src/error/mod.rs +++ b/subxt/src/error/mod.rs @@ -12,11 +12,11 @@ use core::fmt::Debug; pub use dispatch_error::{ ArithmeticError, DispatchError, ModuleError, RawModuleError, TokenError, TransactionalError, }; +pub use scale_decode::Error as DecodeError; +pub use scale_encode::Error as EncodeError; // Re-expose the errors we use from other crates here: pub use crate::metadata::{InvalidMetadataError, Metadata, MetadataError}; -pub use scale_decode::Error as DecodeError; -pub use scale_encode::Error as EncodeError; /// The underlying error enum, generic over the type held by the `Runtime` /// variant. Prefer to use the [`Error`] and [`Error`] aliases over diff --git a/subxt/src/events/events_client.rs b/subxt/src/events/events_client.rs index 0a30f2dc6a..9209382583 100644 --- a/subxt/src/events/events_client.rs +++ b/subxt/src/events/events_client.rs @@ -2,10 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{client::OnlineClientT, error::Error, events::Events, rpc::types::StorageKey, Config}; -use derivative::Derivative; use std::future::Future; +use derivative::Derivative; + +use crate::{client::OnlineClientT, error::Error, events::Events, rpc::types::StorageKey, Config}; + /// A client for working with events. #[derive(Derivative)] #[derivative(Clone(bound = "Client: Clone"))] diff --git a/subxt/src/events/events_type.rs b/subxt/src/events/events_type.rs index cf43cea162..2b305f08c1 100644 --- a/subxt/src/events/events_type.rs +++ b/subxt/src/events/events_type.rs @@ -4,6 +4,11 @@ //! A representation of a block of events. +use std::sync::Arc; + +use codec::{Compact, Decode}; +use derivative::Derivative; + use super::{Phase, StaticEvent}; use crate::{ client::OnlineClientT, @@ -12,9 +17,6 @@ use crate::{ metadata::{DecodeWithMetadata, EventMetadata}, Config, Metadata, }; -use codec::{Compact, Decode}; -use derivative::Derivative; -use std::sync::Arc; /// A collection of events obtained from a block, bundled with the necessary /// information needed to decode and iterate over them. @@ -426,15 +428,17 @@ pub trait RootEvent: Sized { /// Event related test utilities used outside this module. #[cfg(test)] pub(crate) mod test_utils { - use super::*; - use crate::{Config, SubstrateConfig}; + use std::convert::TryFrom; + use codec::Encode; use frame_metadata::{ v15::{ExtrinsicMetadata, PalletEventMetadata, PalletMetadata, RuntimeMetadataV15}, RuntimeMetadataPrefixed, }; use scale_info::{meta_type, TypeInfo}; - use std::convert::TryFrom; + + use super::*; + use crate::{Config, SubstrateConfig}; /// An "outer" events enum containing exactly one event. #[derive( @@ -576,13 +580,14 @@ pub(crate) mod test_utils { #[cfg(test)] mod tests { + use codec::Encode; + use scale_info::TypeInfo; + use scale_value::Value; + use super::{ test_utils::{event_record, events, events_raw, AllEvents}, *, }; - use codec::Encode; - use scale_info::TypeInfo; - use scale_value::Value; /// Build a fake wrapped metadata. fn metadata() -> Metadata { diff --git a/subxt/src/lib.rs b/subxt/src/lib.rs index f7eeca7bc3..25102965f3 100644 --- a/subxt/src/lib.rs +++ b/subxt/src/lib.rs @@ -38,12 +38,11 @@ pub mod book; // Suppress an unused dependency warning because tokio is // only used in example code snippets at the time of writing. -#[cfg(test)] -use tokio as _; - // Used to enable the js feature for wasm. #[cfg(target_arch = "wasm32")] pub use getrandom as _; +#[cfg(test)] +use tokio as _; #[cfg(all(feature = "jsonrpsee-ws", feature = "jsonrpsee-web"))] std::compile_error!( diff --git a/subxt/src/metadata/hash_cache.rs b/subxt/src/metadata/hash_cache.rs index 0ece71c788..285031b6fc 100644 --- a/subxt/src/metadata/hash_cache.rs +++ b/subxt/src/metadata/hash_cache.rs @@ -2,9 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use parking_lot::RwLock; use std::{borrow::Cow, collections::HashMap}; +use parking_lot::RwLock; + /// A cache with the simple goal of storing 32 byte hashes against root+item keys #[derive(Default, Debug)] pub struct HashCache { diff --git a/subxt/src/metadata/metadata_type.rs b/subxt/src/metadata/metadata_type.rs index c24065c1b6..0e9f33ac9f 100644 --- a/subxt/src/metadata/metadata_type.rs +++ b/subxt/src/metadata/metadata_type.rs @@ -2,15 +2,17 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use super::hash_cache::HashCache; +use std::{collections::HashMap, convert::TryFrom, sync::Arc}; + use codec::Error as CodecError; use frame_metadata::{ - v15::PalletConstantMetadata, v15::RuntimeMetadataV15, v15::StorageEntryMetadata, + v15::{PalletConstantMetadata, RuntimeMetadataV15, StorageEntryMetadata}, RuntimeMetadata, RuntimeMetadataPrefixed, META_RESERVED, }; use parking_lot::RwLock; use scale_info::{form::PortableForm, PortableRegistry, Type}; -use std::{collections::HashMap, convert::TryFrom, sync::Arc}; + +use super::hash_cache::HashCache; /// Metadata error originated from inspecting the internal representation of the runtime metadata. #[derive(Debug, thiserror::Error, PartialEq, Eq)] @@ -723,13 +725,14 @@ impl TryFrom for Metadata { #[cfg(test)] mod tests { - use super::*; use frame_metadata::v15::{ ExtrinsicMetadata, PalletCallMetadata, PalletMetadata, PalletStorageMetadata, StorageEntryModifier, StorageEntryType, }; use scale_info::{meta_type, TypeInfo}; + use super::*; + fn load_metadata() -> Metadata { // Extrinsic needs to contain at least the generic type parameter "Call" // for the metadata to be valid. diff --git a/subxt/src/metadata/mod.rs b/subxt/src/metadata/mod.rs index d46793ee40..86770abab3 100644 --- a/subxt/src/metadata/mod.rs +++ b/subxt/src/metadata/mod.rs @@ -9,11 +9,9 @@ mod hash_cache; mod metadata_location; mod metadata_type; +pub use decode_encode_traits::{DecodeWithMetadata, EncodeWithMetadata}; pub use metadata_location::MetadataLocation; - pub use metadata_type::{ ErrorMetadata, EventMetadata, ExtrinsicMetadata, InvalidMetadataError, Metadata, MetadataError, PalletMetadata, RuntimeFnMetadata, }; - -pub use decode_encode_traits::{DecodeWithMetadata, EncodeWithMetadata}; diff --git a/subxt/src/rpc/jsonrpsee_impl.rs b/subxt/src/rpc/jsonrpsee_impl.rs index 538d24d742..b03a9978c8 100644 --- a/subxt/src/rpc/jsonrpsee_impl.rs +++ b/subxt/src/rpc/jsonrpsee_impl.rs @@ -2,8 +2,6 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use super::{RpcClientT, RpcFuture, RpcSubscription}; -use crate::error::RpcError; use futures::stream::{StreamExt, TryStreamExt}; use jsonrpsee::{ core::{ @@ -15,6 +13,9 @@ use jsonrpsee::{ }; use serde_json::value::RawValue; +use super::{RpcClientT, RpcFuture, RpcSubscription}; +use crate::error::RpcError; + struct Params(Option>); impl ToRpcParams for Params { diff --git a/subxt/src/rpc/mod.rs b/subxt/src/rpc/mod.rs index 98c76e7998..80fb2da5ad 100644 --- a/subxt/src/rpc/mod.rs +++ b/subxt/src/rpc/mod.rs @@ -56,9 +56,7 @@ pub mod types; // Expose the `Rpc` struct. pub use rpc::*; - +pub use rpc_client::{rpc_params, RpcClient, RpcParams, Subscription}; pub use rpc_client_t::{ RawValue, RpcClientT, RpcFuture, RpcSubscription, RpcSubscriptionId, RpcSubscriptionStream, }; - -pub use rpc_client::{rpc_params, RpcClient, RpcParams, Subscription}; diff --git a/subxt/src/rpc/rpc.rs b/subxt/src/rpc/rpc.rs index f4914eea69..ab44e50dc3 100644 --- a/subxt/src/rpc/rpc.rs +++ b/subxt/src/rpc/rpc.rs @@ -37,13 +37,12 @@ use codec::{Decode, Encode}; use frame_metadata::RuntimeMetadataPrefixed; use serde::Serialize; -use crate::{error::Error, utils::PhantomDataSendSync, Config, Metadata}; - use super::{ rpc_params, types::{self, ChainHeadEvent, FollowEvent}, RpcClient, RpcClientT, Subscription, }; +use crate::{error::Error, utils::PhantomDataSendSync, Config, Metadata}; /// Client for substrate rpc interfaces pub struct Rpc { diff --git a/subxt/src/rpc/rpc_client.rs b/subxt/src/rpc/rpc_client.rs index e5e408d4f8..6010d562e8 100644 --- a/subxt/src/rpc/rpc_client.rs +++ b/subxt/src/rpc/rpc_client.rs @@ -2,12 +2,14 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use super::{RpcClientT, RpcSubscription, RpcSubscriptionId}; -use crate::error::Error; +use std::{pin::Pin, sync::Arc, task::Poll}; + use futures::{Stream, StreamExt}; use serde::{de::DeserializeOwned, Serialize}; use serde_json::value::RawValue; -use std::{pin::Pin, sync::Arc, task::Poll}; + +use super::{RpcClientT, RpcSubscription, RpcSubscriptionId}; +use crate::error::Error; /// A concrete wrapper around an [`RpcClientT`] which exposes the udnerlying interface via some /// higher level methods that make it a little easier to work with. diff --git a/subxt/src/rpc/rpc_client_t.rs b/subxt/src/rpc/rpc_client_t.rs index 64576d0968..932eeabc55 100644 --- a/subxt/src/rpc/rpc_client_t.rs +++ b/subxt/src/rpc/rpc_client_t.rs @@ -2,13 +2,14 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::error::RpcError; -use futures::Stream; use std::{future::Future, pin::Pin}; +use futures::Stream; // Re-exporting for simplicity since it's used a bunch in the trait definition. pub use serde_json::value::RawValue; +use crate::error::RpcError; + /// Any RPC client which implements this can be used in our [`super::Rpc`] type /// to talk to a node. /// diff --git a/subxt/src/rpc/types.rs b/subxt/src/rpc/types.rs index 2500507da0..b84d0b34ed 100644 --- a/subxt/src/rpc/types.rs +++ b/subxt/src/rpc/types.rs @@ -4,14 +4,15 @@ //! Types sent to/from the Substrate RPC interface. -use crate::{metadata::Metadata, Config}; +use std::collections::HashMap; + use codec::{Decode, Encode}; use primitive_types::U256; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; // Subscription types are returned from some calls, so expose it with the rest of the returned types. pub use super::rpc_client::Subscription; +use crate::{metadata::Metadata, Config}; /// An error dry running an extrinsic. #[derive(Debug, PartialEq, Eq)] @@ -730,9 +731,10 @@ impl From> for TransactionEvent { /// Serialize and deserialize helper as string. mod as_string { - use super::*; use serde::Deserializer; + use super::*; + pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result { String::deserialize(deserializer)? .parse() diff --git a/subxt/src/runtime_api/runtime_client.rs b/subxt/src/runtime_api/runtime_client.rs index a785a4259f..ec27085db7 100644 --- a/subxt/src/runtime_api/runtime_client.rs +++ b/subxt/src/runtime_api/runtime_client.rs @@ -2,12 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use super::runtime_types::RuntimeApi; - -use crate::{client::OnlineClientT, error::Error, Config}; -use derivative::Derivative; use std::{future::Future, marker::PhantomData}; +use derivative::Derivative; + +use super::runtime_types::RuntimeApi; +use crate::{client::OnlineClientT, error::Error, Config}; + /// Execute runtime API calls. #[derive(Derivative)] #[derivative(Clone(bound = "Client: Clone"))] diff --git a/subxt/src/runtime_api/runtime_payload.rs b/subxt/src/runtime_api/runtime_payload.rs index c264742e84..0ad7a69f79 100644 --- a/subxt/src/runtime_api/runtime_payload.rs +++ b/subxt/src/runtime_api/runtime_payload.rs @@ -3,12 +3,12 @@ // see LICENSE for license details. use core::marker::PhantomData; -use scale_encode::EncodeAsFields; -use scale_value::Composite; use std::borrow::Cow; -use crate::dynamic::DecodedValueThunk; -use crate::{metadata::DecodeWithMetadata, Error, Metadata}; +use scale_encode::EncodeAsFields; +use scale_value::Composite; + +use crate::{dynamic::DecodedValueThunk, metadata::DecodeWithMetadata, Error, Metadata}; /// This represents a runtime API payload that can call into the runtime of node. /// diff --git a/subxt/src/runtime_api/runtime_types.rs b/subxt/src/runtime_api/runtime_types.rs index 8f9fd5dd21..e53db9ae4e 100644 --- a/subxt/src/runtime_api/runtime_types.rs +++ b/subxt/src/runtime_api/runtime_types.rs @@ -2,12 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{client::OnlineClientT, error::Error, metadata::DecodeWithMetadata, Config}; -use codec::Decode; -use derivative::Derivative; use std::{future::Future, marker::PhantomData}; +use codec::Decode; +use derivative::Derivative; + use super::RuntimeApiPayload; +use crate::{client::OnlineClientT, error::Error, metadata::DecodeWithMetadata, Config}; /// Execute runtime API calls. #[derive(Derivative)] diff --git a/subxt/src/storage/mod.rs b/subxt/src/storage/mod.rs index 8fac6bfca0..832f67bbf3 100644 --- a/subxt/src/storage/mod.rs +++ b/subxt/src/storage/mod.rs @@ -11,7 +11,6 @@ mod storage_type; pub mod utils; pub use storage_client::StorageClient; - pub use storage_type::{KeyIter, Storage}; // Re-export as this is used in the public API in this module: diff --git a/subxt/src/storage/storage_address.rs b/subxt/src/storage/storage_address.rs index 527d8c31bd..5d16db9ac4 100644 --- a/subxt/src/storage/storage_address.rs +++ b/subxt/src/storage/storage_address.rs @@ -2,15 +2,17 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::borrow::Cow; + +use frame_metadata::v15::{StorageEntryType, StorageHasher}; +use scale_info::TypeDef; + use crate::{ dynamic::{DecodedValueThunk, Value}, error::{Error, StorageAddressError}, metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata}, utils::{Encoded, Static}, }; -use frame_metadata::v15::{StorageEntryType, StorageHasher}; -use scale_info::TypeDef; -use std::borrow::Cow; /// This represents a storage address. Anything implementing this trait /// can be used to fetch and iterate over storage entries. diff --git a/subxt/src/storage/storage_client.rs b/subxt/src/storage/storage_client.rs index 64a0af8a00..401387858a 100644 --- a/subxt/src/storage/storage_client.rs +++ b/subxt/src/storage/storage_client.rs @@ -2,18 +2,19 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::{future::Future, marker::PhantomData}; + +use derivative::Derivative; + use super::{ storage_type::{validate_storage_address, Storage}, utils, StorageAddress, }; - use crate::{ client::{OfflineClientT, OnlineClientT}, error::Error, Config, }; -use derivative::Derivative; -use std::{future::Future, marker::PhantomData}; /// Query the runtime storage. #[derive(Derivative)] diff --git a/subxt/src/storage/storage_type.rs b/subxt/src/storage/storage_type.rs index 84c554af6c..22cd789a7f 100644 --- a/subxt/src/storage/storage_type.rs +++ b/subxt/src/storage/storage_type.rs @@ -2,6 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::{future::Future, marker::PhantomData}; + +use derivative::Derivative; +use frame_metadata::v15::StorageEntryType; +use scale_info::form::PortableForm; + use super::storage_address::{StorageAddress, Yes}; use crate::{ client::OnlineClientT, @@ -10,10 +16,6 @@ use crate::{ rpc::types::{StorageData, StorageKey}, Config, }; -use derivative::Derivative; -use frame_metadata::v15::StorageEntryType; -use scale_info::form::PortableForm; -use std::{future::Future, marker::PhantomData}; /// Query the runtime storage. #[derive(Derivative)] diff --git a/subxt/src/tx/mod.rs b/subxt/src/tx/mod.rs index 0eb75c3496..364677826b 100644 --- a/subxt/src/tx/mod.rs +++ b/subxt/src/tx/mod.rs @@ -18,7 +18,6 @@ mod tx_progress; // feature if we want to avoid needing sp_core and sp_runtime. #[cfg(feature = "substrate-compat")] pub use self::signer::PairSigner; - pub use self::{ signer::Signer, tx_client::{SubmittableExtrinsic, TxClient}, diff --git a/subxt/src/tx/signer.rs b/subxt/src/tx/signer.rs index 8f3b40abc4..fdfbbaa08f 100644 --- a/subxt/src/tx/signer.rs +++ b/subxt/src/tx/signer.rs @@ -31,14 +31,15 @@ pub use pair_signer::PairSigner; // packages like sp_keyring and such, and so relies on sp_core and sp_runtime to be included. #[cfg(feature = "substrate-compat")] mod pair_signer { - use super::Signer; - use crate::Config; use sp_core::Pair as PairT; use sp_runtime::{ traits::{IdentifyAccount, Verify}, AccountId32 as SpAccountId32, MultiSignature as SpMultiSignature, }; + use super::Signer; + use crate::Config; + /// A [`Signer`] implementation that can be constructed from an [`sp_core::Pair`]. #[derive(Clone, Debug)] pub struct PairSigner { diff --git a/subxt/src/tx/tx_client.rs b/subxt/src/tx/tx_client.rs index 58b59bc67b..50aca7412e 100644 --- a/subxt/src/tx/tx_client.rs +++ b/subxt/src/tx/tx_client.rs @@ -8,6 +8,8 @@ use codec::{Compact, Encode}; use derivative::Derivative; use sp_core_hashing::blake2_256; +// This is returned from an API below, so expose it here. +pub use crate::rpc::types::DryRunResult; use crate::{ client::{OfflineClientT, OnlineClientT}, config::{Config, ExtrinsicParams, Hasher}, @@ -16,9 +18,6 @@ use crate::{ utils::{Encoded, PhantomDataSendSync}, }; -// This is returned from an API below, so expose it here. -pub use crate::rpc::types::DryRunResult; - /// A client for working with transactions. #[derive(Derivative)] #[derivative(Clone(bound = "Client: Clone"))] diff --git a/subxt/src/tx/tx_payload.rs b/subxt/src/tx/tx_payload.rs index 894cade163..c9452f754a 100644 --- a/subxt/src/tx/tx_payload.rs +++ b/subxt/src/tx/tx_payload.rs @@ -5,11 +5,13 @@ //! This module contains the trait and types used to represent //! transactions that can be submitted. -use crate::{dynamic::Value, error::Error, metadata::Metadata}; +use std::{borrow::Cow, sync::Arc}; + use codec::Encode; use scale_encode::EncodeAsFields; use scale_value::{Composite, ValueDef, Variant}; -use std::{borrow::Cow, sync::Arc}; + +use crate::{dynamic::Value, error::Error, metadata::Metadata}; /// This represents a transaction payload that can be submitted /// to a node. diff --git a/subxt/src/tx/tx_progress.rs b/subxt/src/tx/tx_progress.rs index 97aa77e8c3..b5e76048bb 100644 --- a/subxt/src/tx/tx_progress.rs +++ b/subxt/src/tx/tx_progress.rs @@ -6,6 +6,9 @@ use std::task::Poll; +use derivative::Derivative; +use futures::{Stream, StreamExt}; + use crate::{ client::OnlineClientT, error::{DispatchError, Error, RpcError, TransactionError}, @@ -13,8 +16,6 @@ use crate::{ rpc::types::{Subscription, SubstrateTxStatus}, Config, }; -use derivative::Derivative; -use futures::{Stream, StreamExt}; /// This struct represents a subscription to the progress of some transaction. #[derive(Derivative)] @@ -413,6 +414,7 @@ mod test { use std::pin::Pin; use futures::Stream; + use serde_json::value::RawValue; use crate::{ client::{OfflineClientT, OnlineClientT}, @@ -423,8 +425,6 @@ mod test { Config, Error, SubstrateConfig, }; - use serde_json::value::RawValue; - type MockTxProgress = TxProgress; type MockHash = scale_encode::EncodeAsType for DecodedBits { #[cfg(test)] mod tests { - use super::*; - use core::fmt::Debug; use bitvec::vec::BitVec; use codec::Decode as _; + use super::*; + // NOTE: We don't use `bitvec::order` types in our implementation, since we // don't want to depend on `bitvec`. Rather than reimplementing the unsafe // trait on our types here for testing purposes, we simply convert and diff --git a/subxt/src/utils/mod.rs b/subxt/src/utils/mod.rs index b6a371fe44..80f9c1869e 100644 --- a/subxt/src/utils/mod.rs +++ b/subxt/src/utils/mod.rs @@ -11,18 +11,16 @@ mod multi_signature; mod static_type; mod wrapper_opaque; +pub use account_id::AccountId32; use codec::{Decode, Encode}; use derivative::Derivative; - -pub use account_id::AccountId32; pub use multi_address::MultiAddress; pub use multi_signature::MultiSignature; -pub use static_type::Static; -pub use wrapper_opaque::WrapperKeepOpaque; - // Used in codegen #[doc(hidden)] pub use primitive_types::{H160, H256, H512}; +pub use static_type::Static; +pub use wrapper_opaque::WrapperKeepOpaque; /// Wraps an already encoded byte vector, prevents being encoded as a raw byte vector as part of /// the transaction payload diff --git a/subxt/src/utils/wrapper_opaque.rs b/subxt/src/utils/wrapper_opaque.rs index f5da348682..133e3cb77c 100644 --- a/subxt/src/utils/wrapper_opaque.rs +++ b/subxt/src/utils/wrapper_opaque.rs @@ -2,12 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use super::PhantomDataSendSync; use codec::{Compact, Decode, DecodeAll, Encode}; use derivative::Derivative; use scale_decode::{IntoVisitor, Visitor}; use scale_encode::EncodeAsType; +use super::PhantomDataSendSync; + /// A wrapper for any type `T` which implement encode/decode in a way compatible with `Vec`. /// [`WrapperKeepOpaque`] stores the type only in its opaque format, aka as a `Vec`. To /// access the real type `T` [`Self::try_decode`] needs to be used. diff --git a/testing/integration-tests/src/blocks/mod.rs b/testing/integration-tests/src/blocks/mod.rs index bf9e707997..7c7df98bb3 100644 --- a/testing/integration-tests/src/blocks/mod.rs +++ b/testing/integration-tests/src/blocks/mod.rs @@ -2,13 +2,14 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{pair_signer, test_context, utils::node_runtime}; use codec::Compact; use frame_metadata::RuntimeMetadataPrefixed; use futures::StreamExt; use sp_keyring::AccountKeyring; use subxt::blocks::BlocksClient; +use crate::{pair_signer, test_context, utils::node_runtime}; + // Check that we can subscribe to non-finalized blocks. #[tokio::test] async fn non_finalized_headers_subscription() -> Result<(), subxt::Error> { diff --git a/testing/integration-tests/src/client/mod.rs b/testing/integration-tests/src/client/mod.rs index aeaa30ec43..5d3bebf706 100644 --- a/testing/integration-tests/src/client/mod.rs +++ b/testing/integration-tests/src/client/mod.rs @@ -2,15 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{ - pair_signer, test_context, test_context_with, - utils::{node_runtime, wait_for_blocks}, -}; use assert_matches::assert_matches; use codec::{Compact, Decode, Encode}; use frame_metadata::RuntimeMetadataPrefixed; -use sp_core::storage::well_known_keys; -use sp_core::{sr25519::Pair as Sr25519Pair, Pair}; +use sp_core::{sr25519::Pair as Sr25519Pair, storage::well_known_keys, Pair}; use sp_keyring::AccountKeyring; use subxt::{ error::{DispatchError, Error, TokenError}, @@ -22,6 +17,11 @@ use subxt::{ utils::AccountId32, }; +use crate::{ + pair_signer, test_context, test_context_with, + utils::{node_runtime, wait_for_blocks}, +}; + #[tokio::test] async fn insert_key() { let ctx = test_context_with(AccountKeyring::Bob).await; diff --git a/testing/integration-tests/src/frame/balances.rs b/testing/integration-tests/src/frame/balances.rs index 8868d84697..ed09f06e89 100644 --- a/testing/integration-tests/src/frame/balances.rs +++ b/testing/integration-tests/src/frame/balances.rs @@ -2,10 +2,6 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{ - node_runtime::{self, balances, runtime_types, system}, - pair_signer, test_context, -}; use codec::Decode; use sp_core::Pair; use sp_keyring::AccountKeyring; @@ -14,6 +10,11 @@ use subxt::{ utils::{AccountId32, MultiAddress}, }; +use crate::{ + node_runtime::{self, balances, runtime_types, system}, + pair_signer, test_context, +}; + #[tokio::test] async fn tx_basic_transfer() -> Result<(), subxt::Error> { let alice = pair_signer(AccountKeyring::Alice.pair()); diff --git a/testing/integration-tests/src/frame/contracts.rs b/testing/integration-tests/src/frame/contracts.rs index ba6a3a3907..cb17499c36 100644 --- a/testing/integration-tests/src/frame/contracts.rs +++ b/testing/integration-tests/src/frame/contracts.rs @@ -2,7 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use sp_core::sr25519::Pair; use sp_keyring::AccountKeyring; +use subxt::{ + tx::{PairSigner, TxProgress}, + utils::MultiAddress, + Config, Error, OnlineClient, SubstrateConfig, +}; use crate::{ node_runtime::{ @@ -13,12 +19,6 @@ use crate::{ }, test_context, TestContext, }; -use sp_core::sr25519::Pair; -use subxt::{ - tx::{PairSigner, TxProgress}, - utils::MultiAddress, - Config, Error, OnlineClient, SubstrateConfig, -}; struct ContractsTestContext { cxt: TestContext, diff --git a/testing/integration-tests/src/frame/staking.rs b/testing/integration-tests/src/frame/staking.rs index 8c89fec42b..1402739976 100644 --- a/testing/integration-tests/src/frame/staking.rs +++ b/testing/integration-tests/src/frame/staking.rs @@ -2,6 +2,11 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use assert_matches::assert_matches; +use sp_core::{sr25519, Pair}; +use sp_keyring::AccountKeyring; +use subxt::error::{DispatchError, Error}; + use crate::{ node_runtime::{ self, @@ -13,10 +18,6 @@ use crate::{ }, pair_signer, test_context, }; -use assert_matches::assert_matches; -use sp_core::{sr25519, Pair}; -use sp_keyring::AccountKeyring; -use subxt::error::{DispatchError, Error}; /// Helper function to generate a crypto pair from seed fn get_from_seed(seed: &str) -> sr25519::Pair { diff --git a/testing/integration-tests/src/frame/sudo.rs b/testing/integration-tests/src/frame/sudo.rs index 82833f0e1e..7fce2e0265 100644 --- a/testing/integration-tests/src/frame/sudo.rs +++ b/testing/integration-tests/src/frame/sudo.rs @@ -2,6 +2,8 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use sp_keyring::AccountKeyring; + use crate::{ node_runtime::{ self, @@ -10,7 +12,6 @@ use crate::{ }, pair_signer, test_context, }; -use sp_keyring::AccountKeyring; type Call = runtime_types::kitchensink_runtime::RuntimeCall; type BalancesCall = runtime_types::pallet_balances::pallet::Call; diff --git a/testing/integration-tests/src/frame/system.rs b/testing/integration-tests/src/frame/system.rs index b8777025ac..bd6af864ff 100644 --- a/testing/integration-tests/src/frame/system.rs +++ b/testing/integration-tests/src/frame/system.rs @@ -2,12 +2,13 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use assert_matches::assert_matches; +use sp_keyring::AccountKeyring; + use crate::{ node_runtime::{self, system}, pair_signer, test_context, }; -use assert_matches::assert_matches; -use sp_keyring::AccountKeyring; #[tokio::test] async fn storage_account() -> Result<(), subxt::Error> { diff --git a/testing/integration-tests/src/lib.rs b/testing/integration-tests/src/lib.rs index 9b68870e7b..2860aea457 100644 --- a/testing/integration-tests/src/lib.rs +++ b/testing/integration-tests/src/lib.rs @@ -24,9 +24,6 @@ mod storage; #[cfg(test)] use test_runtime::node_runtime; -#[cfg(test)] -use utils::*; - // We don't use this dependency, but it's here so that we // can enable logging easily if need be. Add this to a test // to enable tracing for it: @@ -34,3 +31,5 @@ use utils::*; // tracing_subscriber::fmt::init(); #[cfg(test)] use tracing_subscriber as _; +#[cfg(test)] +use utils::*; diff --git a/testing/integration-tests/src/metadata/validation.rs b/testing/integration-tests/src/metadata/validation.rs index d5a8642bc9..d177cd4244 100644 --- a/testing/integration-tests/src/metadata/validation.rs +++ b/testing/integration-tests/src/metadata/validation.rs @@ -2,7 +2,6 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, test_context, TestContext}; use frame_metadata::{ v15::{ ExtrinsicMetadata, PalletCallMetadata, PalletMetadata, PalletStorageMetadata, @@ -16,6 +15,8 @@ use scale_info::{ }; use subxt::{Metadata, OfflineClient, SubstrateConfig}; +use crate::{node_runtime, test_context, TestContext}; + async fn metadata_to_api( metadata: RuntimeMetadataV15, ctx: &TestContext, diff --git a/testing/integration-tests/src/runtime_api/mod.rs b/testing/integration-tests/src/runtime_api/mod.rs index c70b1fdfd2..9784b3406c 100644 --- a/testing/integration-tests/src/runtime_api/mod.rs +++ b/testing/integration-tests/src/runtime_api/mod.rs @@ -2,10 +2,11 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, pair_signer, test_context}; use sp_keyring::AccountKeyring; use subxt::utils::AccountId32; +use crate::{node_runtime, pair_signer, test_context}; + #[tokio::test] async fn account_nonce() -> Result<(), subxt::Error> { let ctx = test_context().await; diff --git a/testing/integration-tests/src/storage/mod.rs b/testing/integration-tests/src/storage/mod.rs index eb2a1021c4..36ea490f55 100644 --- a/testing/integration-tests/src/storage/mod.rs +++ b/testing/integration-tests/src/storage/mod.rs @@ -2,10 +2,11 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{node_runtime, pair_signer, test_context, utils::wait_for_blocks}; use sp_keyring::AccountKeyring; use subxt::utils::AccountId32; +use crate::{node_runtime, pair_signer, test_context, utils::wait_for_blocks}; + #[tokio::test] async fn storage_plain_lookup() -> Result<(), subxt::Error> { let ctx = test_context().await; diff --git a/testing/integration-tests/src/utils/context.rs b/testing/integration-tests/src/utils/context.rs index 6aa1374f64..ab36b78203 100644 --- a/testing/integration-tests/src/utils/context.rs +++ b/testing/integration-tests/src/utils/context.rs @@ -2,12 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -pub(crate) use crate::{node_runtime, TestNodeProcess}; - use sp_core::sr25519::Pair; use sp_keyring::AccountKeyring; use subxt::{tx::PairSigner, SubstrateConfig}; +pub(crate) use crate::{node_runtime, TestNodeProcess}; + /// substrate node should be installed on the $PATH const SUBSTRATE_NODE_PATH: &str = "substrate"; diff --git a/testing/integration-tests/src/utils/node_proc.rs b/testing/integration-tests/src/utils/node_proc.rs index dd4adfe091..ef539757b5 100644 --- a/testing/integration-tests/src/utils/node_proc.rs +++ b/testing/integration-tests/src/utils/node_proc.rs @@ -2,8 +2,9 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use sp_keyring::AccountKeyring; use std::ffi::{OsStr, OsString}; + +use sp_keyring::AccountKeyring; use substrate_runner::SubstrateNode; use subxt::{Config, OnlineClient}; diff --git a/testing/substrate-runner/src/lib.rs b/testing/substrate-runner/src/lib.rs index 2b0dd1a047..b447706cc8 100644 --- a/testing/substrate-runner/src/lib.rs +++ b/testing/substrate-runner/src/lib.rs @@ -4,11 +4,13 @@ mod error; -use std::borrow::Cow; -use std::collections::HashMap; -use std::ffi::OsString; -use std::io::{BufRead, BufReader, Read}; -use std::process::{self, Command}; +use std::{ + borrow::Cow, + collections::HashMap, + ffi::OsString, + io::{BufRead, BufReader, Read}, + process::{self, Command}, +}; pub use error::Error; diff --git a/testing/test-runtime/build.rs b/testing/test-runtime/build.rs index bdd45d08bc..e81486d48b 100644 --- a/testing/test-runtime/build.rs +++ b/testing/test-runtime/build.rs @@ -2,8 +2,9 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use codec::{Decode, Encode}; use std::{env, fs, path::Path}; + +use codec::{Decode, Encode}; use substrate_runner::{Error as SubstrateNodeError, SubstrateNode}; static SUBSTRATE_BIN_ENV_VAR: &str = "SUBSTRATE_NODE_PATH"; @@ -100,13 +101,11 @@ mod client { pub use jsonrpsee::{ client_transport::ws::{InvalidUri, Receiver, Sender, Uri, WsTransportClientBuilder}, core::{ - client::{Client, ClientBuilder}, - Error, + client::{Client, ClientBuilder, ClientT}, + rpc_params, Error, }, }; - pub use jsonrpsee::core::{client::ClientT, rpc_params}; - /// Build WS RPC client from URL pub async fn build(url: &str) -> Result { let (sender, receiver) = ws_transport(url).await?; diff --git a/testing/ui-tests/src/dispatch_errors.rs b/testing/ui-tests/src/dispatch_errors.rs index 327b50bc1c..84050c0a15 100644 --- a/testing/ui-tests/src/dispatch_errors.rs +++ b/testing/ui-tests/src/dispatch_errors.rs @@ -2,11 +2,12 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use frame_metadata::RuntimeMetadataPrefixed; + use crate::utils::{ dispatch_error::{ArrayDispatchError, LegacyDispatchError, NamedFieldDispatchError}, generate_metadata_from_pallets_custom_dispatch_error, }; -use frame_metadata::RuntimeMetadataPrefixed; pub fn metadata_array_dispatch_error() -> RuntimeMetadataPrefixed { generate_metadata_from_pallets_custom_dispatch_error::(vec![]) diff --git a/testing/ui-tests/src/utils/mod.rs b/testing/ui-tests/src/utils/mod.rs index 9c8a1c86fa..dc200182a6 100644 --- a/testing/ui-tests/src/utils/mod.rs +++ b/testing/ui-tests/src/utils/mod.rs @@ -13,10 +13,9 @@ use frame_metadata::{ }, RuntimeMetadataPrefixed, }; -use scale_info::{meta_type, IntoPortable, TypeInfo}; - pub use metadata_test_runner::MetadataTestRunner; pub use pallet_metadata_test_runner::PalletMetadataTestRunner; +use scale_info::{meta_type, IntoPortable, TypeInfo}; /// Given some pallet metadata, generate a [`RuntimeMetadataPrefixed`] struct. /// We default to a useless extrinsic type, and register a fake `DispatchError` diff --git a/testing/ui-tests/src/utils/pallet_metadata_test_runner.rs b/testing/ui-tests/src/utils/pallet_metadata_test_runner.rs index e87c755f23..84043b43ca 100644 --- a/testing/ui-tests/src/utils/pallet_metadata_test_runner.rs +++ b/testing/ui-tests/src/utils/pallet_metadata_test_runner.rs @@ -2,9 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. +use std::io::Read; + use codec::{Decode, Encode}; use frame_metadata::{v15::RuntimeMetadataV15, RuntimeMetadataPrefixed}; -use std::io::Read; use subxt_metadata::{metadata_v14_to_latest, retain_metadata_pallets}; static TEST_DIR_PREFIX: &str = "subxt_generated_pallets_ui_tests_";