From a349daaf45ff9b5a507055319f2d97f3fbc18efb Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Wed, 17 Jan 2024 14:11:38 +0100 Subject: [PATCH] broken commit, prelude but no replacement of all std types --- Cargo.lock | 20 ++++++ Cargo.toml | 4 +- subxt/Cargo.toml | 14 ++-- subxt/src/backend/legacy/mod.rs | 1 + subxt/src/backend/legacy/rpc_methods.rs | 1 + subxt/src/backend/mod.rs | 1 + subxt/src/backend/rpc/jsonrpsee_impl.rs | 1 + subxt/src/backend/rpc/rpc_client.rs | 1 + subxt/src/backend/rpc/rpc_client_t.rs | 1 + subxt/src/backend/unstable/follow_stream.rs | 1 + .../backend/unstable/follow_stream_driver.rs | 1 + .../backend/unstable/follow_stream_unpin.rs | 1 + subxt/src/backend/unstable/mod.rs | 1 + subxt/src/backend/unstable/rpc_methods.rs | 1 + subxt/src/backend/unstable/storage_items.rs | 1 + subxt/src/blocks/block_types.rs | 1 + subxt/src/blocks/blocks_client.rs | 1 + subxt/src/blocks/extrinsic_types.rs | 2 +- subxt/src/client/light_client/builder.rs | 1 + subxt/src/client/light_client/mod.rs | 1 + subxt/src/client/light_client/rpc.rs | 1 + subxt/src/client/offline_client.rs | 1 + subxt/src/client/online_client.rs | 1 + subxt/src/config/extrinsic_params.rs | 1 + subxt/src/config/mod.rs | 1 + subxt/src/config/signed_extensions.rs | 1 + subxt/src/constants/constant_address.rs | 1 + subxt/src/constants/constants_client.rs | 1 + .../src/custom_values/custom_value_address.rs | 1 + .../src/custom_values/custom_values_client.rs | 1 + subxt/src/dynamic.rs | 2 +- subxt/src/error/dispatch_error.rs | 1 + subxt/src/error/mod.rs | 2 + subxt/src/events/events_client.rs | 1 + subxt/src/events/events_type.rs | 1 + subxt/src/lib.rs | 2 + subxt/src/metadata/decode_encode_traits.rs | 1 + subxt/src/metadata/metadata_type.rs | 2 +- subxt/src/prelude.rs | 61 ++++++++++++++++ subxt/src/runtime_api/runtime_client.rs | 1 + subxt/src/runtime_api/runtime_payload.rs | 1 + subxt/src/runtime_api/runtime_types.rs | 1 + subxt/src/storage/storage_address.rs | 1 + subxt/src/storage/storage_client.rs | 1 + subxt/src/storage/storage_type.rs | 1 + subxt/src/storage/utils.rs | 1 + subxt/src/tx/tx_client.rs | 2 + subxt/src/tx/tx_payload.rs | 1 + subxt/src/tx/tx_progress.rs | 1 + subxt/src/utils/mod.rs | 1 + subxt/src/utils/wrapper_opaque.rs | 2 +- testing/no-std-tests/Cargo.toml | 24 +++++++ testing/no-std-tests/rust-toolchain | 1 + testing/no-std-tests/src/main.rs | 71 +++++++++++++++++++ 54 files changed, 236 insertions(+), 13 deletions(-) create mode 100644 subxt/src/prelude.rs create mode 100644 testing/no-std-tests/Cargo.toml create mode 100644 testing/no-std-tests/rust-toolchain create mode 100644 testing/no-std-tests/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index c0c7edece2..c1f907556e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2343,6 +2343,12 @@ version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +[[package]] +name = "libc_alloc" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a835c038b748123287f9fb1743d565e7c635879997f43c345a18a026690364e" + [[package]] name = "libm" version = "0.2.8" @@ -2541,6 +2547,19 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" +[[package]] +name = "no-std-tests" +version = "0.0.0" +dependencies = [ + "hex", + "libc", + "libc_alloc", + "parity-scale-codec", + "scale-info", + "subxt", + "subxt-metadata", +] + [[package]] name = "nodrop" version = "0.1.14" @@ -4367,6 +4386,7 @@ dependencies = [ "base58", "bitvec", "blake2", + "cfg-if", "derivative", "either", "frame-metadata 16.0.0", diff --git a/Cargo.toml b/Cargo.toml index d52a1126e2..8f1ee54a8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,13 @@ members = [ "testing/test-runtime", "testing/integration-tests", "testing/ui-tests", + "testing/no-std-tests", "testing/generate-custom-metadata", "macro", "metadata", "signer", "subxt", - "scripts/artifacts" + "scripts/artifacts", ] # We exclude any crates that would depend on non mutually @@ -56,6 +57,7 @@ assert_matches = "1.5.0" base58 = { version = "0.2.0" } bitvec = { version = "1", default-features = false } blake2 = { version = "0.10.6", default-features = false } +cfg-if = "1.0" clap = { version = "4.4.16", features = ["derive", "cargo"] } criterion = "0.4" codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index f0b0c04ce5..a7df1696a1 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -20,16 +20,13 @@ workspace = true [features] # For dev and documentation reasons we enable more features than are often desired. # it's recommended to use `--no-default-features` and then select what you need. -default = ["jsonrpsee", "native"] +default = ["std", "jsonrpsee", "native"] + +std = ["bitvec/std"] # Enable this for native (ie non web/wasm builds). # Exactly 1 of "web" and "native" is expected. -native = [ - "jsonrpsee?/async-client", - "jsonrpsee?/client-ws-transport-native-tls", - "subxt-lightclient?/native", - "tokio-util" -] +native = ["jsonrpsee?/async-client", "jsonrpsee?/client-ws-transport-native-tls", "subxt-lightclient?/native", "tokio-util"] # Enable this for web/wasm builds. # Exactly 1 of "web" and "native" is expected. @@ -55,6 +52,7 @@ unstable-light-client = ["subxt-lightclient", "tokio-stream"] [dependencies] async-trait = { workspace = true } +cfg-if = { workspace = true } codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] } scale-info = { workspace = true } scale-value = { workspace = true } @@ -68,7 +66,7 @@ serde_json = { workspace = true, features = ["raw_value"] } thiserror = { workspace = true } tracing = { workspace = true } frame-metadata = { workspace = true } -derivative = { workspace = true } +derivative = { workspace = true, features = ["use_core"] } either = { workspace = true } # Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256: diff --git a/subxt/src/backend/legacy/mod.rs b/subxt/src/backend/legacy/mod.rs index cffb3f4475..b4c0acb4f7 100644 --- a/subxt/src/backend/legacy/mod.rs +++ b/subxt/src/backend/legacy/mod.rs @@ -13,6 +13,7 @@ use crate::backend::{ TransactionStatus, }; use crate::{config::Header, Config, Error}; +use crate::prelude::*; use async_trait::async_trait; use futures::{future, future::Either, stream, Future, FutureExt, Stream, StreamExt}; use std::collections::VecDeque; diff --git a/subxt/src/backend/legacy/rpc_methods.rs b/subxt/src/backend/legacy/rpc_methods.rs index 4dde85ee98..82fd2a1af6 100644 --- a/subxt/src/backend/legacy/rpc_methods.rs +++ b/subxt/src/backend/legacy/rpc_methods.rs @@ -7,6 +7,7 @@ use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription}; use crate::metadata::Metadata; use crate::{Config, Error}; +use crate::prelude::*; use codec::Decode; use derivative::Derivative; use primitive_types::U256; diff --git a/subxt/src/backend/mod.rs b/subxt/src/backend/mod.rs index 3db06818b3..76ae28daad 100644 --- a/subxt/src/backend/mod.rs +++ b/subxt/src/backend/mod.rs @@ -13,6 +13,7 @@ pub mod unstable; use crate::error::Error; use crate::metadata::Metadata; use crate::Config; +use crate::prelude::*; use async_trait::async_trait; use codec::{Decode, Encode}; use futures::{Stream, StreamExt}; diff --git a/subxt/src/backend/rpc/jsonrpsee_impl.rs b/subxt/src/backend/rpc/jsonrpsee_impl.rs index 5db8864ef6..81864d5dd2 100644 --- a/subxt/src/backend/rpc/jsonrpsee_impl.rs +++ b/subxt/src/backend/rpc/jsonrpsee_impl.rs @@ -4,6 +4,7 @@ use super::{RawRpcFuture, RawRpcSubscription, RpcClientT}; use crate::error::RpcError; +use crate::prelude::*; use futures::stream::{StreamExt, TryStreamExt}; use jsonrpsee::{ core::{ diff --git a/subxt/src/backend/rpc/rpc_client.rs b/subxt/src/backend/rpc/rpc_client.rs index d960c010db..12a854c684 100644 --- a/subxt/src/backend/rpc/rpc_client.rs +++ b/subxt/src/backend/rpc/rpc_client.rs @@ -4,6 +4,7 @@ use super::{RawRpcSubscription, RpcClientT}; use crate::error::Error; +use crate::prelude::*; use futures::{Stream, StreamExt}; use serde::{de::DeserializeOwned, Serialize}; use serde_json::value::RawValue; diff --git a/subxt/src/backend/rpc/rpc_client_t.rs b/subxt/src/backend/rpc/rpc_client_t.rs index 98d349d17c..da3bc42cde 100644 --- a/subxt/src/backend/rpc/rpc_client_t.rs +++ b/subxt/src/backend/rpc/rpc_client_t.rs @@ -3,6 +3,7 @@ // see LICENSE for license details. use crate::error::RpcError; +use crate::prelude::*; use futures::Stream; use std::{future::Future, pin::Pin}; diff --git a/subxt/src/backend/unstable/follow_stream.rs b/subxt/src/backend/unstable/follow_stream.rs index 9474f7a302..84dd97168f 100644 --- a/subxt/src/backend/unstable/follow_stream.rs +++ b/subxt/src/backend/unstable/follow_stream.rs @@ -5,6 +5,7 @@ use super::rpc_methods::{FollowEvent, UnstableRpcMethods}; use crate::config::Config; use crate::error::Error; +use crate::prelude::*; use futures::{FutureExt, Stream, StreamExt}; use std::future::Future; use std::pin::Pin; diff --git a/subxt/src/backend/unstable/follow_stream_driver.rs b/subxt/src/backend/unstable/follow_stream_driver.rs index 482bfd2543..2f62bcebe7 100644 --- a/subxt/src/backend/unstable/follow_stream_driver.rs +++ b/subxt/src/backend/unstable/follow_stream_driver.rs @@ -6,6 +6,7 @@ use super::follow_stream_unpin::{BlockRef, FollowStreamMsg, FollowStreamUnpin}; use crate::backend::unstable::rpc_methods::{FollowEvent, Initialized, RuntimeEvent}; use crate::config::BlockHash; use crate::error::Error; +use crate::prelude::*; use futures::stream::{Stream, StreamExt}; use std::collections::{HashMap, HashSet, VecDeque}; use std::ops::DerefMut; diff --git a/subxt/src/backend/unstable/follow_stream_unpin.rs b/subxt/src/backend/unstable/follow_stream_unpin.rs index fe064f0707..54a7ab98f5 100644 --- a/subxt/src/backend/unstable/follow_stream_unpin.rs +++ b/subxt/src/backend/unstable/follow_stream_unpin.rs @@ -9,6 +9,7 @@ use crate::backend::unstable::rpc_methods::{ }; use crate::config::{BlockHash, Config}; use crate::error::Error; +use crate::prelude::*; use futures::stream::{FuturesUnordered, Stream, StreamExt}; use std::collections::{HashMap, HashSet}; use std::future::Future; diff --git a/subxt/src/backend/unstable/mod.rs b/subxt/src/backend/unstable/mod.rs index a9fc8658a0..49af9b9208 100644 --- a/subxt/src/backend/unstable/mod.rs +++ b/subxt/src/backend/unstable/mod.rs @@ -28,6 +28,7 @@ use crate::backend::{ use crate::config::BlockHash; use crate::error::{Error, RpcError}; use crate::Config; +use crate::prelude::*; use async_trait::async_trait; use follow_stream_driver::{FollowStreamDriver, FollowStreamDriverHandle}; use futures::{Stream, StreamExt}; diff --git a/subxt/src/backend/unstable/rpc_methods.rs b/subxt/src/backend/unstable/rpc_methods.rs index 331cb5459b..ea48dbf6c2 100644 --- a/subxt/src/backend/unstable/rpc_methods.rs +++ b/subxt/src/backend/unstable/rpc_methods.rs @@ -9,6 +9,7 @@ use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription}; use crate::config::BlockHash; use crate::{Config, Error}; +use crate::prelude::*; use derivative::Derivative; use futures::{Stream, StreamExt}; use serde::{Deserialize, Serialize}; diff --git a/subxt/src/backend/unstable/storage_items.rs b/subxt/src/backend/unstable/storage_items.rs index 73790765ea..0fe968d5db 100644 --- a/subxt/src/backend/unstable/storage_items.rs +++ b/subxt/src/backend/unstable/storage_items.rs @@ -9,6 +9,7 @@ use super::rpc_methods::{ }; use crate::config::Config; use crate::error::{Error, RpcError}; +use crate::prelude::*; use futures::{FutureExt, Stream, StreamExt}; use std::collections::VecDeque; use std::future::Future; diff --git a/subxt/src/blocks/block_types.rs b/subxt/src/blocks/block_types.rs index a1cb01ec25..c2f294c803 100644 --- a/subxt/src/blocks/block_types.rs +++ b/subxt/src/blocks/block_types.rs @@ -11,6 +11,7 @@ use crate::{ events, runtime_api::RuntimeApi, storage::Storage, + prelude::*, }; use codec::{Decode, Encode}; diff --git a/subxt/src/blocks/blocks_client.rs b/subxt/src/blocks/blocks_client.rs index 9ec031a35a..d4a60ed833 100644 --- a/subxt/src/blocks/blocks_client.rs +++ b/subxt/src/blocks/blocks_client.rs @@ -9,6 +9,7 @@ use crate::{ config::Config, error::{BlockError, Error}, utils::PhantomDataSendSync, + prelude::*, }; use derivative::Derivative; use futures::StreamExt; diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index 92f70d565c..d35bd444de 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -11,7 +11,7 @@ use crate::{ metadata::types::PalletMetadata, Metadata, }; - +use crate::prelude::*; use crate::config::signed_extensions::{ ChargeAssetTxPayment, ChargeTransactionPayment, CheckNonce, }; diff --git a/subxt/src/client/light_client/builder.rs b/subxt/src/client/light_client/builder.rs index ce0f7c6aca..f121f08464 100644 --- a/subxt/src/client/light_client/builder.rs +++ b/subxt/src/client/light_client/builder.rs @@ -8,6 +8,7 @@ use crate::client::RawLightClient; use crate::macros::{cfg_jsonrpsee_native, cfg_jsonrpsee_web}; use crate::utils::validate_url_is_secure; use crate::{config::Config, error::Error, OnlineClient}; +use crate::prelude::*; use std::num::NonZeroU32; use subxt_lightclient::{smoldot, AddedChain}; diff --git a/subxt/src/client/light_client/mod.rs b/subxt/src/client/light_client/mod.rs index a4b116652e..05a636fa84 100644 --- a/subxt/src/client/light_client/mod.rs +++ b/subxt/src/client/light_client/mod.rs @@ -20,6 +20,7 @@ use crate::{ tx::TxClient, OnlineClient, }; +use crate::prelude::*; pub use builder::{LightClientBuilder, RawLightClientBuilder}; use derivative::Derivative; use subxt_lightclient::LightClientRpcError; diff --git a/subxt/src/client/light_client/rpc.rs b/subxt/src/client/light_client/rpc.rs index 1186528ec6..6aff8c4c7d 100644 --- a/subxt/src/client/light_client/rpc.rs +++ b/subxt/src/client/light_client/rpc.rs @@ -7,6 +7,7 @@ use crate::{ backend::rpc::{RawRpcFuture, RawRpcSubscription, RpcClientT}, error::{Error, RpcError}, }; +use crate::prelude::*; use futures::StreamExt; use serde_json::value::RawValue; use tokio_stream::wrappers::UnboundedReceiverStream; diff --git a/subxt/src/client/offline_client.rs b/subxt/src/client/offline_client.rs index 4477e21b7a..fc4ebf180c 100644 --- a/subxt/src/client/offline_client.rs +++ b/subxt/src/client/offline_client.rs @@ -8,6 +8,7 @@ use crate::{ events::EventsClient, runtime_api::RuntimeApiClient, storage::StorageClient, tx::TxClient, Config, Metadata, }; +use crate::prelude::*; use derivative::Derivative; use std::sync::Arc; diff --git a/subxt/src/client/online_client.rs b/subxt/src/client/online_client.rs index f4e2f8c723..6f7879a468 100644 --- a/subxt/src/client/online_client.rs +++ b/subxt/src/client/online_client.rs @@ -17,6 +17,7 @@ use crate::{ tx::TxClient, Config, Metadata, }; +use crate::prelude::*; use derivative::Derivative; use futures::future; use std::sync::{Arc, RwLock}; diff --git a/subxt/src/config/extrinsic_params.rs b/subxt/src/config/extrinsic_params.rs index 42f3b620af..c5a3c3a371 100644 --- a/subxt/src/config/extrinsic_params.rs +++ b/subxt/src/config/extrinsic_params.rs @@ -8,6 +8,7 @@ //! implementation of this that will work in many cases. use crate::{client::OfflineClientT, Config}; +use crate::prelude::*; use core::fmt::Debug; /// An error that can be emitted when trying to construct an instance of [`ExtrinsicParams`], diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index ddfa2466c7..2b27577858 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -16,6 +16,7 @@ pub mod signed_extensions; pub mod substrate; use crate::macros::cfg_substrate_compat; +use crate::prelude::*; use codec::{Decode, Encode}; use core::fmt::Debug; use scale_decode::DecodeAsType; diff --git a/subxt/src/config/signed_extensions.rs b/subxt/src/config/signed_extensions.rs index f0864cee61..a3c58d55b0 100644 --- a/subxt/src/config/signed_extensions.rs +++ b/subxt/src/config/signed_extensions.rs @@ -10,6 +10,7 @@ use super::extrinsic_params::{ExtrinsicParams, ExtrinsicParamsEncoder, ExtrinsicParamsError}; use crate::utils::Era; use crate::{client::OfflineClientT, Config}; +use crate::prelude::*; use codec::{Compact, Encode}; use core::fmt::Debug; use derivative::Derivative; diff --git a/subxt/src/constants/constant_address.rs b/subxt/src/constants/constant_address.rs index e9a0eb37b0..c0d621bc22 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -3,6 +3,7 @@ // see LICENSE for license details. use crate::{dynamic::DecodedValueThunk, metadata::DecodeWithMetadata}; +use crate::prelude::*; use derivative::Derivative; use std::borrow::Cow; diff --git a/subxt/src/constants/constants_client.rs b/subxt/src/constants/constants_client.rs index de688bba6b..47138d71ac 100644 --- a/subxt/src/constants/constants_client.rs +++ b/subxt/src/constants/constants_client.rs @@ -9,6 +9,7 @@ use crate::{ metadata::DecodeWithMetadata, Config, }; +use crate::prelude::*; use derivative::Derivative; /// A client for accessing constants. diff --git a/subxt/src/custom_values/custom_value_address.rs b/subxt/src/custom_values/custom_value_address.rs index f8034a161b..59097a7441 100644 --- a/subxt/src/custom_values/custom_value_address.rs +++ b/subxt/src/custom_values/custom_value_address.rs @@ -3,6 +3,7 @@ use std::marker::PhantomData; use crate::dynamic::DecodedValueThunk; use crate::metadata::DecodeWithMetadata; +use crate::prelude::*; /// This represents the address of a custom value in in the metadata. /// Anything, that implements the [CustomValueAddress] trait can be used, to fetch diff --git a/subxt/src/custom_values/custom_values_client.rs b/subxt/src/custom_values/custom_values_client.rs index 3b8c1f54c2..b634ac4553 100644 --- a/subxt/src/custom_values/custom_values_client.rs +++ b/subxt/src/custom_values/custom_values_client.rs @@ -3,6 +3,7 @@ use crate::custom_values::custom_value_address::{CustomValueAddress, Yes}; use crate::error::MetadataError; use crate::metadata::DecodeWithMetadata; use crate::{Config, Error}; +use crate::prelude::*; use derivative::Derivative; /// A client for accessing custom values stored in the metadata. diff --git a/subxt/src/dynamic.rs b/subxt/src/dynamic.rs index 2801feb683..3cb345a2d5 100644 --- a/subxt/src/dynamic.rs +++ b/subxt/src/dynamic.rs @@ -10,7 +10,7 @@ use crate::{ metadata::{DecodeWithMetadata, Metadata}, }; use scale_decode::DecodeAsType; - +use crate::prelude::*; pub use scale_value::{At, Value}; /// A [`scale_value::Value`] type endowed with contextual information diff --git a/subxt/src/error/dispatch_error.rs b/subxt/src/error/dispatch_error.rs index 817a441dd6..b510de6c6f 100644 --- a/subxt/src/error/dispatch_error.rs +++ b/subxt/src/error/dispatch_error.rs @@ -9,6 +9,7 @@ use crate::metadata::{DecodeWithMetadata, Metadata}; use core::fmt::Debug; use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType}; use std::borrow::Cow; +use crate::prelude::*; use super::{Error, MetadataError}; diff --git a/subxt/src/error/mod.rs b/subxt/src/error/mod.rs index 78c5528012..f7f622bdc0 100644 --- a/subxt/src/error/mod.rs +++ b/subxt/src/error/mod.rs @@ -20,10 +20,12 @@ pub use dispatch_error::{ // Re-expose the errors we use from other crates here: pub use crate::config::ExtrinsicParamsError; pub use crate::metadata::Metadata; +use crate::prelude::*; pub use scale_decode::Error as DecodeError; pub use scale_encode::Error as EncodeError; pub use subxt_metadata::TryFromError as MetadataTryFromError; + /// The underlying error enum, generic over the type held by the `Runtime` /// variant. Prefer to use the [`Error`] and [`Error`] aliases over /// using this type directly. diff --git a/subxt/src/events/events_client.rs b/subxt/src/events/events_client.rs index 834e6cd64f..7b0dc1e2e9 100644 --- a/subxt/src/events/events_client.rs +++ b/subxt/src/events/events_client.rs @@ -4,6 +4,7 @@ use crate::backend::{Backend, BackendExt, BlockRef}; use crate::{client::OnlineClientT, error::Error, events::Events, Config}; +use crate::prelude::*; use derivative::Derivative; use std::future::Future; diff --git a/subxt/src/events/events_type.rs b/subxt/src/events/events_type.rs index 831268ad00..5f94a4f766 100644 --- a/subxt/src/events/events_type.rs +++ b/subxt/src/events/events_type.rs @@ -12,6 +12,7 @@ use crate::{ metadata::types::PalletMetadata, Config, Metadata, }; +use crate::prelude::*; use codec::{Compact, Decode}; use derivative::Derivative; use scale_decode::DecodeAsType; diff --git a/subxt/src/lib.rs b/subxt/src/lib.rs index b50880e1ea..b3ddbb3666 100644 --- a/subxt/src/lib.rs +++ b/subxt/src/lib.rs @@ -11,6 +11,7 @@ //! Take a look at [the Subxt guide](book) to learn more about how to use Subxt. #![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(not(feature = "std"), no_std)] #[cfg(any( all(feature = "web", feature = "native"), @@ -56,6 +57,7 @@ pub mod runtime_api; pub mod storage; pub mod tx; pub mod utils; +pub mod prelude; // Internal helper macros #[macro_use] diff --git a/subxt/src/metadata/decode_encode_traits.rs b/subxt/src/metadata/decode_encode_traits.rs index 81dbaea131..1ae6ded98e 100644 --- a/subxt/src/metadata/decode_encode_traits.rs +++ b/subxt/src/metadata/decode_encode_traits.rs @@ -4,6 +4,7 @@ use super::Metadata; use crate::error::Error; +use crate::prelude::*; /// This trait is implemented for all types that also implement [`scale_decode::DecodeAsType`]. pub trait DecodeWithMetadata: Sized { diff --git a/subxt/src/metadata/metadata_type.rs b/subxt/src/metadata/metadata_type.rs index 29ae567afa..9f21d78a71 100644 --- a/subxt/src/metadata/metadata_type.rs +++ b/subxt/src/metadata/metadata_type.rs @@ -3,7 +3,7 @@ // see LICENSE for license details. use crate::error::MetadataError; - +use crate::prelude::*; use std::sync::Arc; /// A cheaply clone-able representation of the runtime metadata received from a node. diff --git a/subxt/src/prelude.rs b/subxt/src/prelude.rs new file mode 100644 index 0000000000..85d2641a4e --- /dev/null +++ b/subxt/src/prelude.rs @@ -0,0 +1,61 @@ +// 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. + +//! Exports from `std`, `core` and `alloc` crates. +//! +//! Guarantees a stable interface between `std` and `no_std` modes. + +#[cfg(not(feature = "std"))] +extern crate alloc; + +use cfg_if::cfg_if; + +cfg_if! { + if #[cfg(feature = "std")] { + pub use std::{ + any, + borrow, + boxed::{Box}, + cmp, + collections, + fmt, + format, + hash, + marker::{PhantomData}, + mem, + num, + ops, + string, + sync, + time, + vec::{vec, Vec}, + rc, + iter, + }; + } else { + pub use alloc::{ + borrow, + boxed::{Box}, + collections, + format, + string, + sync, + vec::{vec, Vec}, + rc + }; + + pub use core::{ + any, + cmp, + fmt, + hash, + marker::{PhantomData}, + mem, + num, + ops, + time, + iter, + }; + } +} diff --git a/subxt/src/runtime_api/runtime_client.rs b/subxt/src/runtime_api/runtime_client.rs index 5770285b83..19c4d583a4 100644 --- a/subxt/src/runtime_api/runtime_client.rs +++ b/subxt/src/runtime_api/runtime_client.rs @@ -5,6 +5,7 @@ use super::runtime_types::RuntimeApi; use crate::{backend::BlockRef, client::OnlineClientT, error::Error, Config}; +use crate::prelude::*; use derivative::Derivative; use std::{future::Future, marker::PhantomData}; diff --git a/subxt/src/runtime_api/runtime_payload.rs b/subxt/src/runtime_api/runtime_payload.rs index cd5a3355b8..b05258548d 100644 --- a/subxt/src/runtime_api/runtime_payload.rs +++ b/subxt/src/runtime_api/runtime_payload.rs @@ -11,6 +11,7 @@ use std::borrow::Cow; use crate::dynamic::DecodedValueThunk; use crate::error::MetadataError; use crate::{metadata::DecodeWithMetadata, Error, Metadata}; +use crate::prelude::*; /// 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 3ea8c93947..da4d45ce11 100644 --- a/subxt/src/runtime_api/runtime_types.rs +++ b/subxt/src/runtime_api/runtime_types.rs @@ -9,6 +9,7 @@ use crate::{ metadata::DecodeWithMetadata, Config, }; +use crate::prelude::*; use codec::Decode; use derivative::Derivative; use std::{future::Future, marker::PhantomData}; diff --git a/subxt/src/storage/storage_address.rs b/subxt/src/storage/storage_address.rs index 893474b518..78c6674cdc 100644 --- a/subxt/src/storage/storage_address.rs +++ b/subxt/src/storage/storage_address.rs @@ -8,6 +8,7 @@ use crate::{ metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata}, utils::{Encoded, Static}, }; +use crate::prelude::*; use derivative::Derivative; use scale_info::TypeDef; use std::borrow::Cow; diff --git a/subxt/src/storage/storage_client.rs b/subxt/src/storage/storage_client.rs index 55ab339aea..204ab9fcb0 100644 --- a/subxt/src/storage/storage_client.rs +++ b/subxt/src/storage/storage_client.rs @@ -12,6 +12,7 @@ use crate::{ error::Error, Config, }; +use crate::prelude::*; use derivative::Derivative; use std::{future::Future, marker::PhantomData}; diff --git a/subxt/src/storage/storage_type.rs b/subxt/src/storage/storage_type.rs index 2669c1abce..74538c854f 100644 --- a/subxt/src/storage/storage_type.rs +++ b/subxt/src/storage/storage_type.rs @@ -11,6 +11,7 @@ use crate::{ metadata::{DecodeWithMetadata, Metadata}, Config, }; +use crate::prelude::*; use codec::Decode; use derivative::Derivative; use futures::StreamExt; diff --git a/subxt/src/storage/utils.rs b/subxt/src/storage/utils.rs index 728a581baf..9a83765510 100644 --- a/subxt/src/storage/utils.rs +++ b/subxt/src/storage/utils.rs @@ -8,6 +8,7 @@ use super::StorageAddress; use crate::{error::Error, metadata::Metadata}; +use crate::prelude::*; /// Return the root of a given [`StorageAddress`]: hash the pallet name and entry name /// and append those bytes to the output. diff --git a/subxt/src/tx/tx_client.rs b/subxt/src/tx/tx_client.rs index 6bf6c9ab57..57400facd9 100644 --- a/subxt/src/tx/tx_client.rs +++ b/subxt/src/tx/tx_client.rs @@ -9,9 +9,11 @@ use crate::{ client::{OfflineClientT, OnlineClientT}, config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder, Hasher}, error::{Error, MetadataError}, + prelude::*, tx::{Signer as SignerT, TxPayload, TxProgress}, utils::{Encoded, PhantomDataSendSync}, }; +use crate::prelude::*; use codec::{Compact, Decode, Encode}; use derivative::Derivative; use sp_core_hashing::blake2_256; diff --git a/subxt/src/tx/tx_payload.rs b/subxt/src/tx/tx_payload.rs index 508a6a99e6..76ee693123 100644 --- a/subxt/src/tx/tx_payload.rs +++ b/subxt/src/tx/tx_payload.rs @@ -10,6 +10,7 @@ use crate::{ error::{Error, MetadataError}, metadata::Metadata, }; +use crate::prelude::*; use codec::Encode; use scale_encode::EncodeAsFields; use scale_value::{Composite, ValueDef, Variant}; diff --git a/subxt/src/tx/tx_progress.rs b/subxt/src/tx/tx_progress.rs index b949de2be4..45f8afa3b8 100644 --- a/subxt/src/tx/tx_progress.rs +++ b/subxt/src/tx/tx_progress.rs @@ -14,6 +14,7 @@ use crate::{ events::EventsClient, Config, }; +use crate::prelude::*; use derivative::Derivative; use futures::{Stream, StreamExt}; diff --git a/subxt/src/utils/mod.rs b/subxt/src/utils/mod.rs index dc9320a303..e5e08754e6 100644 --- a/subxt/src/utils/mod.rs +++ b/subxt/src/utils/mod.rs @@ -15,6 +15,7 @@ mod wrapper_opaque; use crate::error::RpcError; use crate::Error; +use crate::prelude::*; use codec::{Compact, Decode, Encode}; use derivative::Derivative; use url::Url; diff --git a/subxt/src/utils/wrapper_opaque.rs b/subxt/src/utils/wrapper_opaque.rs index 9257405715..0af27d2ee4 100644 --- a/subxt/src/utils/wrapper_opaque.rs +++ b/subxt/src/utils/wrapper_opaque.rs @@ -153,7 +153,7 @@ impl Visitor for WrapperKeepOpaqueVisitor { impl IntoVisitor for WrapperKeepOpaque { type Visitor = WrapperKeepOpaqueVisitor; fn into_visitor() -> Self::Visitor { - WrapperKeepOpaqueVisitor(std::marker::PhantomData) + WrapperKeepOpaqueVisitor(PhantomData) } } diff --git a/testing/no-std-tests/Cargo.toml b/testing/no-std-tests/Cargo.toml new file mode 100644 index 0000000000..ca164b4c3b --- /dev/null +++ b/testing/no-std-tests/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "no-std-tests" +edition = "2021" +publish = false +version = "0.0.0" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +scale-info = { workspace = true, default-features = false, features = ["bit-vec", "derive"] } +codec = { package = "parity-scale-codec", workspace = true, default-features = false, features = ["derive", "bit-vec"] } +subxt = { workspace = true, default-features = false, features = ["native"] } +subxt-metadata = { workspace = true, default-features = false } + +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +libc = { version = "0.2", default-features = false } +libc_alloc = { version = "1.0.6" } + + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" diff --git a/testing/no-std-tests/rust-toolchain b/testing/no-std-tests/rust-toolchain new file mode 100644 index 0000000000..07ade694b1 --- /dev/null +++ b/testing/no-std-tests/rust-toolchain @@ -0,0 +1 @@ +nightly \ No newline at end of file diff --git a/testing/no-std-tests/src/main.rs b/testing/no-std-tests/src/main.rs new file mode 100644 index 0000000000..b375e18ab2 --- /dev/null +++ b/testing/no-std-tests/src/main.rs @@ -0,0 +1,71 @@ +// Copyright 2019-2020 +// Parity Technologies (UK) Ltd. Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#![allow(internal_features)] +#![feature(lang_items, start)] +#![feature(alloc_error_handler)] +#![no_std] + +#[start] +fn start(_argc: isize, _argv: *const *const u8) -> isize { + main(); + 0 +} + +#[lang = "eh_personality"] +#[no_mangle] +pub extern "C" fn rust_eh_personality() {} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + unsafe { + libc::abort(); + } +} + +use libc_alloc::LibcAlloc; + +#[global_allocator] +static ALLOCATOR: LibcAlloc = LibcAlloc; + +////////////////////////////////////////////////////////////////////////////// + +use subxt::utils::H256; + +// Note: Panics in this function will lead to `Aborted (core dumped)` and a non-zero exit status => suitable for CI tests. +fn main() { + let metadata_bytes: &[u8] = include_bytes!("../../../artifacts/polkadot_metadata_small.scale"); + + let genesis_hash = { + let h = "91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"; + let bytes = hex::decode(h).unwrap(); + H256::from_slice(&bytes) + }; + + // // 2. A runtime version (system_version constant on a Substrate node has these): + // let runtime_version = subxt::backend::RuntimeVersion { + // spec_version: 9370, + // transaction_version: 20, + // }; + + // // 3. Metadata (I'll load it from the downloaded metadata, but you can use + // // `subxt metadata > file.scale` to download it): + // let metadata = { + // let bytes: &[u8] = include_bytes!("../polkadot_metadata_small.scale"); + // Metadata::decode(&mut &*bytes).unwrap() + // }; + + // // Create an offline client using the details obtained above: + // let api = OfflineClient::::new(genesis_hash, runtime_version, metadata); +}