diff --git a/Cargo.lock b/Cargo.lock index 685b40afcc..7dc9b6274b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4541,7 +4541,6 @@ dependencies = [ "base58", "bitvec", "blake2", - "cfg-if", "derivative", "derive_more", "either", @@ -4636,7 +4635,7 @@ dependencies = [ "sp-core", "sp-core-hashing", "sp-keyring", - "subxt", + "subxt-core", "thiserror", "zeroize", ] diff --git a/core/Cargo.toml b/core/Cargo.toml index 8435c04209..0b950f4ae9 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -47,7 +47,6 @@ sp-core-hashing = { workspace = true } # Included if the "substrate-compat" feature is enabled. sp-core = { workspace = true, optional = true } sp-runtime = { workspace = true, optional = true } -cfg-if = { workspace = true } either = { workspace = true } [dev-dependencies] diff --git a/core/src/config/extrinsic_params.rs b/core/src/config/extrinsic_params.rs index 9e6396d1b1..f0efbf0153 100644 --- a/core/src/config/extrinsic_params.rs +++ b/core/src/config/extrinsic_params.rs @@ -10,10 +10,9 @@ use crate::client::ClientBase; use super::Config; -use crate::prelude::*; +use alloc::string::String; +use alloc::vec::Vec; use core::fmt::Debug; -use string::String; -use vec::Vec; use derive_more::Display; diff --git a/core/src/config/signed_extensions.rs b/core/src/config/signed_extensions.rs index 2bf6a1bc51..d09704beb2 100644 --- a/core/src/config/signed_extensions.rs +++ b/core/src/config/signed_extensions.rs @@ -10,17 +10,16 @@ use super::extrinsic_params::{ExtrinsicParams, ExtrinsicParamsEncoder, ExtrinsicParamsError}; use super::Config; use crate::client::ClientBase; -use crate::prelude::*; use crate::utils::Era; -use borrow::ToOwned; -use boxed::Box; +use alloc::borrow::ToOwned; +use alloc::boxed::Box; +use alloc::collections::BTreeMap; +use alloc::vec::Vec; use codec::{Compact, Encode}; -use collections::BTreeMap; use core::fmt::Debug; use derivative::Derivative; use scale_decode::DecodeAsType; use scale_info::PortableRegistry; -use vec::Vec; /// A single [`SignedExtension`] has a unique name, but is otherwise the /// same as [`ExtrinsicParams`] in describing how to encode the extra and diff --git a/core/src/config/substrate.rs b/core/src/config/substrate.rs index b8e930c882..a7c5e99215 100644 --- a/core/src/config/substrate.rs +++ b/core/src/config/substrate.rs @@ -5,13 +5,12 @@ //! Substrate specific configuration use super::{Config, DefaultExtrinsicParams, DefaultExtrinsicParamsBuilder, Hasher, Header}; -use crate::prelude::*; pub use crate::utils::{AccountId32, MultiAddress, MultiSignature}; +use alloc::string::String; +use alloc::vec::Vec; use codec::{Decode, Encode}; pub use primitive_types::{H256, U256}; use serde::{Deserialize, Serialize}; -use string::String; -use vec::Vec; /// Default set of commonly used types by Substrate runtimes. // Note: We only use this at the type level, so it should be impossible to @@ -209,7 +208,7 @@ impl<'a> serde::Deserialize<'a> for DigestItem { { let r = impl_serde::serialize::deserialize(de)?; Decode::decode(&mut &r[..]) - .map_err(|e| serde::de::Error::custom(format!("Decode error: {e}"))) + .map_err(|e| serde::de::Error::custom(alloc::format!("Decode error: {e}"))) } } @@ -292,7 +291,7 @@ impl From for NumberOrHex { /// A quick helper to encode some bytes to hex. fn to_hex(bytes: impl AsRef<[u8]>) -> String { - format!("0x{}", hex::encode(bytes.as_ref())) + alloc::format!("0x{}", hex::encode(bytes.as_ref())) } #[cfg(test)] diff --git a/core/src/dynamic.rs b/core/src/dynamic.rs index a1a8aeaa22..c3686b483c 100644 --- a/core/src/dynamic.rs +++ b/core/src/dynamic.rs @@ -6,10 +6,9 @@ //! transactions, storage and constant lookups. use crate::metadata::{DecodeWithMetadata, Metadata}; -use crate::prelude::*; +use alloc::vec::Vec; use scale_decode::DecodeAsType; pub use scale_value::{At, Value}; -use vec::Vec; /// A [`scale_value::Value`] type endowed with contextual information /// regarding what type was used to decode each part of it. This implements diff --git a/core/src/error.rs b/core/src/error.rs index 8ca8c6db6d..038ee74747 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -1,3 +1,4 @@ +use alloc::string::String; use derive_more::{Display, From}; #[derive(Debug, Display, From)] diff --git a/core/src/lib.rs b/core/src/lib.rs index 20d03f0dea..11b8a23eec 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -8,12 +8,13 @@ #![cfg_attr(not(feature = "std"), no_std)] +extern crate alloc; + pub mod client; pub mod config; pub mod dynamic; mod error; pub mod metadata; -pub mod prelude; pub mod signer; pub mod storage; pub mod tx; @@ -26,7 +27,14 @@ pub use config::{ PolkadotExtrinsicParams, SubstrateConfig, SubstrateExtrinsicParams, }; +pub use signer::Signer; + pub use metadata::Metadata; #[macro_use] mod macros; + +mod marker { + /// A unit marker struct that is only used for specialized generics. + pub struct Yes; +} diff --git a/core/src/marker.rs b/core/src/marker.rs new file mode 100644 index 0000000000..aaf7f841f0 --- /dev/null +++ b/core/src/marker.rs @@ -0,0 +1 @@ +pub struct Yes; diff --git a/core/src/metadata/decode_encode_traits.rs b/core/src/metadata/decode_encode_traits.rs index 4b9089a001..3bc4dc87b0 100644 --- a/core/src/metadata/decode_encode_traits.rs +++ b/core/src/metadata/decode_encode_traits.rs @@ -3,8 +3,7 @@ // see LICENSE for license details. use super::Metadata; -use crate::prelude::*; -use vec::Vec; +use alloc::vec::Vec; /// This trait is implemented for all types that also implement [`scale_decode::DecodeAsType`]. pub trait DecodeWithMetadata: Sized { diff --git a/core/src/metadata/metadata_type.rs b/core/src/metadata/metadata_type.rs index 48d822189a..7bd5c5c080 100644 --- a/core/src/metadata/metadata_type.rs +++ b/core/src/metadata/metadata_type.rs @@ -2,9 +2,9 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::{prelude::*, MetadataError}; -use borrow::ToOwned; -use sync::Arc; +use crate::error::MetadataError; +use alloc::borrow::ToOwned; +use alloc::sync::Arc; /// A cheaply clone-able representation of the runtime metadata received from a node. #[derive(Clone, Debug)] diff --git a/core/src/prelude.rs b/core/src/prelude.rs deleted file mode 100644 index 007bd44665..0000000000 --- a/core/src/prelude.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2019-2023 Parity Technologies (UK) Ltd. -// This file is dual-licensed as Apache-2.0 or GPL-3.0. -// see LICENSE for license details. - -#[cfg(not(feature = "std"))] -extern crate alloc; - -use cfg_if::cfg_if; - -cfg_if! { - if #[cfg(feature = "std")] { - #[allow(unused)] - pub use std::{ - any, - borrow, - boxed, - cmp, - collections, - fmt, - format, - hash, - marker, - mem, - num, - ops, - string, - sync, - time, - vec, - rc, - iter, - }; - } else { - #[allow(unused)] - pub use alloc::{ - borrow, - boxed, - collections, - format, - string, - sync, - vec, - rc - }; - #[allow(unused)] - pub use core::{ - any, - cmp, - fmt, - hash, - marker, - mem, - num, - ops, - time, - iter, - }; - } -} diff --git a/core/src/storage/mod.rs b/core/src/storage/mod.rs index e37eb0383a..a1976ecd16 100644 --- a/core/src/storage/mod.rs +++ b/core/src/storage/mod.rs @@ -4,9 +4,12 @@ //! Types associated with accessing and working with storage items. -mod storage_address; +use alloc::vec::Vec; + /// Types representing an address which describes where a storage /// entry lives and how to properly decode it. +pub mod storage_address; + pub mod address { pub use super::storage_address::{ dynamic, make_static_storage_map_key, Address, DynamicAddress, StaticStorageMapKey, diff --git a/core/src/storage/storage_address.rs b/core/src/storage/storage_address.rs index 925b0a012e..49d24598a3 100644 --- a/core/src/storage/storage_address.rs +++ b/core/src/storage/storage_address.rs @@ -11,9 +11,11 @@ use crate::{ use crate::metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata}; use crate::Error; +use alloc::borrow::{Cow, ToOwned}; +use alloc::string::String; +use alloc::vec::Vec; use derivative::Derivative; use scale_info::TypeDef; -use std::borrow::Cow; use subxt_metadata::{StorageEntryType, StorageHasher}; /// This represents a storage address. Anything implementing this trait @@ -58,14 +60,14 @@ pub struct Yes; #[derive(Derivative)] #[derivative( Clone(bound = "StorageKey: Clone"), - Debug(bound = "StorageKey: std::fmt::Debug") + Debug(bound = "StorageKey: core::fmt::Debug") )] pub struct Address { pallet_name: Cow<'static, str>, entry_name: Cow<'static, str>, storage_entry_keys: Vec, validation_hash: Option<[u8; 32]>, - _marker: std::marker::PhantomData<(ReturnTy, Fetchable, Defaultable, Iterable)>, + _marker: core::marker::PhantomData<(ReturnTy, Fetchable, Defaultable, Iterable)>, } /// A typical storage address constructed at runtime rather than via the `subxt` macro; this @@ -89,7 +91,7 @@ where entry_name: Cow::Owned(entry_name.into()), storage_entry_keys: storage_entry_keys.into_iter().collect(), validation_hash: None, - _marker: std::marker::PhantomData, + _marker: core::marker::PhantomData, } } @@ -107,7 +109,7 @@ where entry_name: Cow::Borrowed(entry_name), storage_entry_keys: storage_entry_keys.into_iter().collect(), validation_hash: Some(hash), - _marker: std::marker::PhantomData, + _marker: core::marker::PhantomData, } } @@ -187,7 +189,7 @@ where TypeDef::Tuple(tuple) => { either::Either::Left(tuple.fields.iter().map(|f| f.id)) } - _other => either::Either::Right(std::iter::once(*key_ty)), + _other => either::Either::Right(core::iter::once(*key_ty)), }; if type_ids.len() < self.storage_entry_keys.len() { diff --git a/core/src/tx/mod.rs b/core/src/tx/mod.rs index d9a7c839db..0b7975671c 100644 --- a/core/src/tx/mod.rs +++ b/core/src/tx/mod.rs @@ -5,21 +5,16 @@ //! This module contains the trait and types used to represent //! transactions that can be submitted. -use crate::prelude::*; use crate::Error; use crate::MetadataError; -use crate::{ - dynamic::Value, - metadata::{self, Metadata}, -}; -use borrow::Cow; -use borrow::ToOwned; +use crate::{dynamic::Value, metadata::Metadata}; +use alloc::borrow::{Cow, ToOwned}; +use alloc::string::String; +use alloc::sync::Arc; +use alloc::vec::Vec; use codec::Encode; use scale_encode::EncodeAsFields; use scale_value::{Composite, ValueDef, Variant}; -use string::String; -use sync::Arc; -use vec::Vec; /// This represents a transaction payload that can be submitted /// to a node. diff --git a/core/src/utils/account_id.rs b/core/src/utils/account_id.rs index 7a7ef7949f..28ef331f1d 100644 --- a/core/src/utils/account_id.rs +++ b/core/src/utils/account_id.rs @@ -6,12 +6,12 @@ //! This doesn't contain much functionality itself, but is easy to convert to/from an `sp_core::AccountId32` //! for instance, to gain functionality without forcing a dependency on Substrate crates here. -use crate::prelude::*; +use alloc::string::String; +use alloc::vec; +use alloc::vec::Vec; use codec::{Decode, Encode}; use derive_more::Display; use serde::{Deserialize, Serialize}; -use string::String; -use vec::Vec; /// A 32-byte cryptographic identifier. This is a simplified version of Substrate's /// `sp_core::crypto::AccountId32`. To obtain more functionality, convert this into @@ -145,7 +145,7 @@ impl<'de> Deserialize<'de> for AccountId32 { D: serde::Deserializer<'de>, { AccountId32::from_ss58check(&String::deserialize(deserializer)?) - .map_err(|e| serde::de::Error::custom(format!("{e:?}"))) + .map_err(|e| serde::de::Error::custom(alloc::format!("{e:?}"))) } } diff --git a/core/src/utils/bits.rs b/core/src/utils/bits.rs index 5774cd9fcf..dc19509537 100644 --- a/core/src/utils/bits.rs +++ b/core/src/utils/bits.rs @@ -4,7 +4,8 @@ //! Generic `scale_bits` over `bitvec`-like `BitOrder` and `BitFormat` types. -use crate::prelude::*; +use alloc::vec; +use alloc::vec::Vec; use codec::{Compact, Input}; use core::marker::PhantomData; use scale_bits::{ @@ -12,7 +13,6 @@ use scale_bits::{ Bits, }; use scale_decode::IntoVisitor; -use vec::Vec; /// Associates `bitvec::store::BitStore` trait with corresponding, type-erased `scale_bits::StoreFormat` enum. /// diff --git a/core/src/utils/mod.rs b/core/src/utils/mod.rs index 067c43f3f2..54eaf230ed 100644 --- a/core/src/utils/mod.rs +++ b/core/src/utils/mod.rs @@ -4,11 +4,10 @@ //! Miscellaneous utility helpers. -use crate::prelude::*; -use borrow::ToOwned; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; use codec::{Compact, Decode, Encode}; use derivative::Derivative; -use vec::Vec; mod account_id; pub mod bits; diff --git a/core/src/utils/multi_address.rs b/core/src/utils/multi_address.rs index c742c34937..3a2d97297d 100644 --- a/core/src/utils/multi_address.rs +++ b/core/src/utils/multi_address.rs @@ -6,9 +6,8 @@ //! This doesn't contain much functionality itself, but is easy to convert to/from an `sp_runtime::MultiAddress` //! for instance, to gain functionality without forcing a dependency on Substrate crates here. -use crate::prelude::*; +use alloc::vec::Vec; use codec::{Decode, Encode}; -use vec::Vec; /// A multi-format address wrapper for on-chain accounts. This is a simplified version of Substrate's /// `sp_runtime::MultiAddress`. To obtain more functionality, convert this into that type (this conversion diff --git a/core/src/utils/static_type.rs b/core/src/utils/static_type.rs index 9484706b85..257b2d9eae 100644 --- a/core/src/utils/static_type.rs +++ b/core/src/utils/static_type.rs @@ -2,11 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::prelude::*; +use alloc::vec::Vec; use codec::{Decode, Encode}; use scale_decode::{visitor::DecodeAsTypeResult, IntoVisitor, Visitor}; use scale_encode::EncodeAsType; -use vec::Vec; /// If the type inside this implements [`Encode`], this will implement [`scale_encode::EncodeAsType`]. /// If the type inside this implements [`Decode`], this will implement [`scale_decode::DecodeAsType`]. diff --git a/core/src/utils/unchecked_extrinsic.rs b/core/src/utils/unchecked_extrinsic.rs index 89744ac12a..e661620ec8 100644 --- a/core/src/utils/unchecked_extrinsic.rs +++ b/core/src/utils/unchecked_extrinsic.rs @@ -10,11 +10,10 @@ //! bytes to be re-encoded (length prefixed). use super::{Encoded, Static}; -use crate::prelude::*; +use alloc::vec::Vec; use codec::{Decode, Encode}; use core::marker::PhantomData; use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType, IntoVisitor, Visitor}; -use vec::Vec; /// The unchecked extrinsic from substrate. #[derive(Clone, Debug, Eq, PartialEq, Encode)] diff --git a/core/src/utils/wrapper_opaque.rs b/core/src/utils/wrapper_opaque.rs index 8ca9ca1758..3c73a1bad1 100644 --- a/core/src/utils/wrapper_opaque.rs +++ b/core/src/utils/wrapper_opaque.rs @@ -3,12 +3,11 @@ // see LICENSE for license details. use super::PhantomDataSendSync; -use crate::prelude::*; +use alloc::vec::Vec; use codec::{Compact, Decode, DecodeAll, Encode}; use derivative::Derivative; use scale_decode::{IntoVisitor, Visitor}; use scale_encode::EncodeAsType; -use vec::Vec; /// 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 diff --git a/signer/Cargo.toml b/signer/Cargo.toml index 226237c315..4192e27a09 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -15,7 +15,7 @@ description = "Sign extrinsics to be submitted by Subxt" keywords = ["parity", "subxt", "extrinsic", "signer"] [features] -default = ["sr25519", "ecdsa", "subxt", "native"] +default = ["sr25519", "ecdsa", "subxt"] # Pick the signer implementation(s) you need by enabling the # corresponding features. Note: I had more difficulties getting @@ -26,15 +26,14 @@ ecdsa = ["secp256k1"] # Make the keypair algorithms here compatible with Subxt's Signer trait, # so that they can be used to sign transactions for compatible chains. -subxt = ["dep:subxt"] +subxt = ["dep:subxt-core"] # The getrandom package is used via schnorrkel. We need to enable the JS # feature on it if compiling for the web. -web = ["getrandom/js", "subxt?/web"] -native = ["subxt?/native"] +web = ["getrandom/js"] [dependencies] -subxt = { workspace = true, optional = true, default-features = false } +subxt-core = { workspace = true, optional = true, default-features = false } regex = { workspace = true } hex = { workspace = true } codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] } diff --git a/testing/no-std-tests/Cargo.lock b/testing/no-std-tests/Cargo.lock index d304f1eb85..184ac58900 100644 --- a/testing/no-std-tests/Cargo.lock +++ b/testing/no-std-tests/Cargo.lock @@ -675,9 +675,9 @@ version = "0.34.0" dependencies = [ "base58", "blake2", - "cfg-if", "derivative", "derive_more", + "either", "frame-metadata 16.0.0", "hex", "impl-serde", diff --git a/testing/no-std-tests/src/main.rs b/testing/no-std-tests/src/main.rs index 72d4f35152..2812cae098 100644 --- a/testing/no-std-tests/src/main.rs +++ b/testing/no-std-tests/src/main.rs @@ -36,6 +36,7 @@ extern crate alloc; // Note: Panics in this function will lead to `Aborted (core dumped)` and a non-zero exit status => suitable for CI tests. fn run_tests() { subxt_metadata_test(); + subxt_core_test(); } /// Makes sure, subxt-metadata works in a no-std-context: @@ -49,5 +50,5 @@ fn subxt_metadata_test() { } fn subxt_core_test() { - let era = subxt_core::utils::Era::Immortal; + let _ = subxt_core::utils::Era::Immortal; }