From 70e5118d42a3dc97d3402119d7e9571ccf98b8c0 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Tue, 23 Jan 2024 13:55:12 +0100 Subject: [PATCH] broken fractured commits, only a few errors remaining --- Cargo.lock | 1 + subxt/Cargo.toml | 1 + subxt/src/backend/legacy/mod.rs | 1 - subxt/src/backend/legacy/rpc_methods.rs | 5 +- subxt/src/backend/mod.rs | 1 - subxt/src/backend/rpc/jsonrpsee_impl.rs | 1 - subxt/src/backend/rpc/rpc_client.rs | 5 +- subxt/src/backend/rpc/rpc_client_t.rs | 1 - subxt/src/backend/unstable/follow_stream.rs | 1 - .../backend/unstable/follow_stream_driver.rs | 20 +++--- .../backend/unstable/follow_stream_unpin.rs | 19 +++-- subxt/src/backend/unstable/mod.rs | 72 ++++++++++++------- subxt/src/backend/unstable/rpc_methods.rs | 12 ++-- subxt/src/backend/unstable/storage_items.rs | 1 - subxt/src/blocks/blocks_client.rs | 11 ++- subxt/src/blocks/extrinsic_types.rs | 12 ++-- subxt/src/blocks/mod.rs | 4 ++ subxt/src/client/mod.rs | 3 + subxt/src/client/offline_client.rs | 2 +- subxt/src/client/online_client.rs | 1 - subxt/src/config/extrinsic_params.rs | 9 ++- subxt/src/config/mod.rs | 4 +- subxt/src/config/signed_extensions.rs | 5 +- subxt/src/config/substrate.rs | 6 +- subxt/src/constants/constant_address.rs | 2 +- .../src/custom_values/custom_values_client.rs | 4 +- subxt/src/error/dispatch_error.rs | 2 +- subxt/src/error/mod.rs | 8 +-- subxt/src/events/events_client.rs | 14 +++- subxt/src/events/events_type.rs | 17 +++-- subxt/src/lib.rs | 8 ++- subxt/src/metadata/metadata_type.rs | 4 +- subxt/src/prelude.rs | 8 ++- subxt/src/runtime_api/mod.rs | 8 +++ subxt/src/runtime_api/runtime_client.rs | 7 +- subxt/src/runtime_api/runtime_payload.rs | 5 +- subxt/src/runtime_api/runtime_types.rs | 11 ++- subxt/src/storage/mod.rs | 3 + subxt/src/storage/storage_address.rs | 4 +- subxt/src/storage/storage_client.rs | 19 ++--- subxt/src/storage/storage_type.rs | 1 + subxt/src/tx/mod.rs | 6 +- subxt/src/tx/tx_client.rs | 16 +++-- subxt/src/tx/tx_payload.rs | 4 +- subxt/src/tx/tx_progress.rs | 9 ++- subxt/src/utils/account_id.rs | 1 + subxt/src/utils/mod.rs | 2 +- 47 files changed, 225 insertions(+), 136 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d2303d88c..77ccf476d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4395,6 +4395,7 @@ dependencies = [ "getrandom 0.2.12", "hex", "impl-serde", + "instant", "jsonrpsee", "parity-scale-codec", "primitive-types", diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index bc1a06bc4e..72bd11252b 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -68,6 +68,7 @@ frame-metadata = { workspace = true } derivative = { workspace = true, features = ["use_core"] } derive_more = { workspace = true } either = { workspace = true } +instant = { workspace = true } # Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256: impl-serde = { workspace = true } diff --git a/subxt/src/backend/legacy/mod.rs b/subxt/src/backend/legacy/mod.rs index b4c0acb4f7..cffb3f4475 100644 --- a/subxt/src/backend/legacy/mod.rs +++ b/subxt/src/backend/legacy/mod.rs @@ -13,7 +13,6 @@ 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 c020133453..4dde85ee98 100644 --- a/subxt/src/backend/legacy/rpc_methods.rs +++ b/subxt/src/backend/legacy/rpc_methods.rs @@ -6,7 +6,6 @@ use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription}; use crate::metadata::Metadata; -use crate::prelude::*; use crate::{Config, Error}; use codec::Decode; use derivative::Derivative; @@ -20,7 +19,7 @@ use serde::{Deserialize, Serialize}; #[derivative(Clone(bound = ""), Debug(bound = ""))] pub struct LegacyRpcMethods { client: RpcClient, - _marker: PhantomData, + _marker: std::marker::PhantomData, } impl LegacyRpcMethods { @@ -28,7 +27,7 @@ impl LegacyRpcMethods { pub fn new(client: RpcClient) -> Self { LegacyRpcMethods { client, - _marker: PhantomData, + _marker: std::marker::PhantomData, } } diff --git a/subxt/src/backend/mod.rs b/subxt/src/backend/mod.rs index 76ae28daad..3db06818b3 100644 --- a/subxt/src/backend/mod.rs +++ b/subxt/src/backend/mod.rs @@ -13,7 +13,6 @@ 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 81864d5dd2..5db8864ef6 100644 --- a/subxt/src/backend/rpc/jsonrpsee_impl.rs +++ b/subxt/src/backend/rpc/jsonrpsee_impl.rs @@ -4,7 +4,6 @@ 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 7f5da8e634..d960c010db 100644 --- a/subxt/src/backend/rpc/rpc_client.rs +++ b/subxt/src/backend/rpc/rpc_client.rs @@ -4,7 +4,6 @@ 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; @@ -181,7 +180,7 @@ impl RpcParams { /// [`StreamExt`] extension trait. pub struct RpcSubscription { inner: RawRpcSubscription, - _marker: PhantomData, + _marker: std::marker::PhantomData, } impl std::fmt::Debug for RpcSubscription { @@ -198,7 +197,7 @@ impl RpcSubscription { pub fn new(inner: RawRpcSubscription) -> Self { Self { inner, - _marker: PhantomData, + _marker: std::marker::PhantomData, } } diff --git a/subxt/src/backend/rpc/rpc_client_t.rs b/subxt/src/backend/rpc/rpc_client_t.rs index da3bc42cde..98d349d17c 100644 --- a/subxt/src/backend/rpc/rpc_client_t.rs +++ b/subxt/src/backend/rpc/rpc_client_t.rs @@ -3,7 +3,6 @@ // 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 84dd97168f..9474f7a302 100644 --- a/subxt/src/backend/unstable/follow_stream.rs +++ b/subxt/src/backend/unstable/follow_stream.rs @@ -5,7 +5,6 @@ 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 2f62bcebe7..d32c98a104 100644 --- a/subxt/src/backend/unstable/follow_stream_driver.rs +++ b/subxt/src/backend/unstable/follow_stream_driver.rs @@ -6,7 +6,6 @@ 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; @@ -46,19 +45,20 @@ impl Stream for FollowStreamDriver { type Item = Result<(), Error>; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - let item = match self.inner.poll_next_unpin(cx) { - Poll::Pending => return Poll::Pending, + match self.inner.poll_next_unpin(cx) { + Poll::Pending => Poll::Pending, Poll::Ready(None) => { // Mark ourselves as done so that everything can end. self.shared.done(); - return Poll::Ready(None); + Poll::Ready(None) } - Poll::Ready(Some(Err(e))) => return Poll::Ready(Some(Err(e))), - Poll::Ready(Some(Ok(item))) => item, - }; - - self.shared.push_item(item); - Poll::Ready(Some(Ok(()))) + Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))), + Poll::Ready(Some(Ok(item))) => { + // Push item to any subscribers. + self.shared.push_item(item); + Poll::Ready(Some(Ok(()))) + } + } } } diff --git a/subxt/src/backend/unstable/follow_stream_unpin.rs b/subxt/src/backend/unstable/follow_stream_unpin.rs index 54a7ab98f5..ca00e37690 100644 --- a/subxt/src/backend/unstable/follow_stream_unpin.rs +++ b/subxt/src/backend/unstable/follow_stream_unpin.rs @@ -9,7 +9,6 @@ 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; @@ -75,10 +74,11 @@ impl Stream for FollowStreamUnpin { let mut this = self.as_mut(); loop { - // Poll the unpin tasks while they are completing. if we get back None, then - // no tasks in the list, and if pending, we'll be woken when we can poll again. - if let Poll::Ready(Some(())) = this.unpin_futs.poll_next_unpin(cx) { - continue; + // Poll any queued unpin tasks. + let unpin_futs_are_pending = match this.unpin_futs.poll_next_unpin(cx) { + Poll::Ready(Some(())) => continue, + Poll::Ready(None) => false, + Poll::Pending => true, }; // Poll the inner stream for the next event. @@ -86,9 +86,14 @@ impl Stream for FollowStreamUnpin { return Poll::Pending; }; - // No more progress to be made if inner stream done. let Some(ev) = ev else { - return Poll::Ready(None); + // if the stream is done, but `unpin_futs` are still pending, then + // return pending here so that they are still driven to completion. + // Else, return `Ready(None)` to signal nothing left to do. + return match unpin_futs_are_pending { + true => Poll::Pending, + false => Poll::Ready(None), + }; }; // Error? just return it and do nothing further. diff --git a/subxt/src/backend/unstable/mod.rs b/subxt/src/backend/unstable/mod.rs index 409181ad3a..82a2d50d48 100644 --- a/subxt/src/backend/unstable/mod.rs +++ b/subxt/src/backend/unstable/mod.rs @@ -27,7 +27,6 @@ use crate::backend::{ }; use crate::config::BlockHash; use crate::error::{Error, RpcError}; -use crate::prelude::*; use crate::Config; use async_trait::async_trait; use follow_stream_driver::{FollowStreamDriver, FollowStreamDriverHandle}; @@ -43,7 +42,7 @@ pub use rpc_methods::UnstableRpcMethods; /// Configure and build an [`UnstableBackend`]. pub struct UnstableBackendBuilder { max_block_life: usize, - _marker: PhantomData, + _marker: std::marker::PhantomData, } impl Default for UnstableBackendBuilder { @@ -57,7 +56,7 @@ impl UnstableBackendBuilder { pub fn new() -> Self { Self { max_block_life: usize::MAX, - _marker: PhantomData, + _marker: std::marker::PhantomData, } } @@ -481,24 +480,43 @@ impl Backend for UnstableBackend { // with chainHead_follow. let mut finalized_hash: Option = None; + // Record the start time so that we can time out if things appear to take too long. + let start_instant = instant::Instant::now(); + + // A quick helper to return a generic error. + let err_other = |s: &str| Some(Err(Error::Other(s.into()))); + // Now we can attempt to associate tx events with pinned blocks. let tx_stream = futures::stream::poll_fn(move |cx| { loop { - // Bail early if no more tx events; we don't want to keep polling for pinned blocks. + // Bail early if we're finished; nothing else to do. if done { return Poll::Ready(None); } - // Make a note of new or finalized blocks that have come in since we started the TX. - if let Poll::Ready(Some(seen_block)) = seen_blocks_sub.poll_next_unpin(cx) { - match seen_block { - FollowEvent::Initialized(ev) => { - // Just in case this stream is really slow to start or something.. - seen_blocks.insert( - ev.finalized_block_hash.hash(), - (SeenBlockMarker::Finalized, ev.finalized_block_hash), - ); - } + // Bail if we exceed 4 mins; something very likely went wrong. + if start_instant.elapsed().as_secs() > 240 { + return Poll::Ready(err_other( + "Timeout waiting for the transaction to be finalized", + )); + } + + // Poll for a follow event, and error if the stream has unexpectedly ended. + let follow_ev_poll = match seen_blocks_sub.poll_next_unpin(cx) { + Poll::Ready(None) => { + return Poll::Ready(err_other("chainHead_follow stream ended unexpectedly")) + } + Poll::Ready(Some(follow_ev)) => Poll::Ready(follow_ev), + Poll::Pending => Poll::Pending, + }; + let follow_ev_is_pending = follow_ev_poll.is_pending(); + + // If there was a follow event, then handle it and loop around to see if there are more. + // We want to buffer follow events until we hit Pending, so that we are as up-to-date as possible + // for when we see a BestBlockChanged event, so that we have the best change of already having + // seen the block that it mentions and returning a proper pinned block. + if let Poll::Ready(follow_ev) = follow_ev_poll { + match follow_ev { FollowEvent::NewBlock(ev) => { // Optimization: once we have a `finalized_hash`, we only care about finalized // block refs now and can avoid bothering to save new blocks. @@ -522,7 +540,7 @@ impl Backend for UnstableBackend { // in which we may lose the finaliuzed block that the TX is in. For now, just error if // this happens, to prevent the case in which we never see a finalized block and wait // forever. - return Poll::Ready(Some(Err(Error::Other("chainHead_follow emitted 'stop' event during transaction submission".into())))); + return Poll::Ready(err_other("chainHead_follow emitted 'stop' event during transaction submission")); } _ => {} } @@ -541,25 +559,27 @@ impl Backend for UnstableBackend { }; return Poll::Ready(Some(Ok(ev))); } else { - // Keep waiting for more finalized blocks until we find it (get rid of any other block refs - // now, since none of them were what we were looking for anyway). + // Not found it! If follow ev is pending, then return pending here and wait for + // a new one to come in, else loop around and see if we get another one immediately. seen_blocks.clear(); - continue; + if follow_ev_is_pending { + return Poll::Pending; + } else { + continue; + } } } - // Otherwise, we are still watching for tx events: - let ev = match tx_progress.poll_next_unpin(cx) { + // If we don't have a finalized block yet, we keep polling for tx progress events. + let tx_progress_ev = match tx_progress.poll_next_unpin(cx) { Poll::Pending => return Poll::Pending, - Poll::Ready(None) => { - done = true; - return Poll::Ready(None); - } + Poll::Ready(None) => return Poll::Ready(err_other("No more transaction progress events, but we haven't seen a Finalized one yet")), Poll::Ready(Some(Err(e))) => return Poll::Ready(Some(Err(e))), Poll::Ready(Some(Ok(ev))) => ev, }; + // When we get one, map it to the correct format (or for finalized ev, wait for the pinned block): - let ev = match ev { + let tx_progress_ev = match tx_progress_ev { rpc_methods::TransactionStatus::Finalized { block } => { // We'll wait until we have seen this hash, to try to guarantee // that when we return this event, the corresponding block is @@ -597,7 +617,7 @@ impl Backend for UnstableBackend { } rpc_methods::TransactionStatus::Validated => TransactionStatus::Validated, }; - return Poll::Ready(Some(Ok(ev))); + return Poll::Ready(Some(Ok(tx_progress_ev))); } }); diff --git a/subxt/src/backend/unstable/rpc_methods.rs b/subxt/src/backend/unstable/rpc_methods.rs index a3e914983f..331cb5459b 100644 --- a/subxt/src/backend/unstable/rpc_methods.rs +++ b/subxt/src/backend/unstable/rpc_methods.rs @@ -8,7 +8,6 @@ use crate::backend::rpc::{rpc_params, RpcClient, RpcSubscription}; use crate::config::BlockHash; -use crate::prelude::*; use crate::{Config, Error}; use derivative::Derivative; use futures::{Stream, StreamExt}; @@ -23,7 +22,7 @@ use std::task::Poll; #[derivative(Clone(bound = ""), Debug(bound = ""))] pub struct UnstableRpcMethods { client: RpcClient, - _marker: PhantomData, + _marker: std::marker::PhantomData, } impl UnstableRpcMethods { @@ -31,7 +30,7 @@ impl UnstableRpcMethods { pub fn new(client: RpcClient) -> Self { UnstableRpcMethods { client, - _marker: PhantomData, + _marker: std::marker::PhantomData, } } @@ -747,7 +746,6 @@ fn to_hex(bytes: impl AsRef<[u8]>) -> String { /// Attempt to deserialize either a string or integer into an integer. /// See pub(crate) mod unsigned_number_as_string { - use crate::prelude::*; use serde::de::{Deserializer, Visitor}; use std::fmt; @@ -756,10 +754,10 @@ pub(crate) mod unsigned_number_as_string { where D: Deserializer<'de>, { - deserializer.deserialize_any(NumberVisitor(PhantomData)) + deserializer.deserialize_any(NumberVisitor(std::marker::PhantomData)) } - struct NumberVisitor(PhantomData); + struct NumberVisitor(std::marker::PhantomData); impl<'de, N: From> Visitor<'de> for NumberVisitor { type Value = N; @@ -795,11 +793,11 @@ pub(crate) mod unsigned_number_as_string { /// /// Adapted from pub(crate) mod hashmap_as_tuple_list { - use crate::prelude::*; use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor}; use std::collections::HashMap; use std::fmt; use std::hash::{BuildHasher, Hash}; + use std::marker::PhantomData; /// Deserialize a [`HashMap`] from a list of tuples or object pub fn deserialize<'de, K, V, BH, D>(deserializer: D) -> Result, D::Error> diff --git a/subxt/src/backend/unstable/storage_items.rs b/subxt/src/backend/unstable/storage_items.rs index 0fe968d5db..73790765ea 100644 --- a/subxt/src/backend/unstable/storage_items.rs +++ b/subxt/src/backend/unstable/storage_items.rs @@ -9,7 +9,6 @@ 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/blocks_client.rs b/subxt/src/blocks/blocks_client.rs index d4a60ed833..d0f1515bc8 100644 --- a/subxt/src/blocks/blocks_client.rs +++ b/subxt/src/blocks/blocks_client.rs @@ -4,12 +4,10 @@ use super::Block; use crate::{ - backend::{BlockRef, StreamOfResults}, - client::OnlineClientT, config::Config, error::{BlockError, Error}, - utils::PhantomDataSendSync, prelude::*, + utils::PhantomDataSendSync, }; use derivative::Derivative; use futures::StreamExt; @@ -18,6 +16,12 @@ use std::future::Future; type BlockStream = StreamOfResults; type BlockStreamRes = Result, Error>; +#[cfg(feature = "std")] +use crate::{ + backend::{BlockRef, StreamOfResults}, + client::OnlineClientT, +}; + /// A client for working with blocks. #[derive(Derivative)] #[derivative(Clone(bound = "Client: Clone"))] @@ -36,6 +40,7 @@ impl BlocksClient { } } +#[cfg(feature = "std")] impl BlocksClient where T: Config, diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index 5d71dd8a33..95ffa20579 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -11,18 +11,21 @@ use crate::prelude::*; use crate::utils::strip_compact_prefix; use crate::{ blocks::block_types::{get_events, CachedEvents}, - client::{OfflineClientT, OnlineClientT}, + client::{OfflineClientT}, config::{Config, Hasher}, error::{BlockError, Error, MetadataError}, events, metadata::types::PalletMetadata, Metadata, }; +#[cfg(feature = "std")] +use crate::client::OnlineClientT; + use codec::Decode; use derivative::Derivative; use scale_decode::{DecodeAsFields, DecodeAsType}; -use std::sync::Arc; +use crate::prelude::sync::Arc; /// Trait to uniquely identify the extrinsic's identity from the runtime metadata. /// @@ -102,7 +105,7 @@ where let ids = self.ids; let mut index = 0; - std::iter::from_fn(move || { + core::iter::from_fn(move || { if index == num_extrinsics { None } else { @@ -466,6 +469,7 @@ where } } +#[cfg(feature = "std")] impl ExtrinsicDetails where T: Config, @@ -627,7 +631,7 @@ impl<'a, T: Config> ExtrinsicSignedExtensions<'a, T> { let mut byte_start_idx = 0; let metadata = &self.metadata; - std::iter::from_fn(move || { + core::iter::from_fn(move || { if index == num_signed_extensions { return None; } diff --git a/subxt/src/blocks/mod.rs b/subxt/src/blocks/mod.rs index 7cf2501b9d..0869799257 100644 --- a/subxt/src/blocks/mod.rs +++ b/subxt/src/blocks/mod.rs @@ -4,14 +4,18 @@ //! This module exposes the necessary functionality for working with events. +#[cfg(feature = "std")] mod block_types; mod blocks_client; mod extrinsic_types; /// A reference to a block. +#[cfg(feature = "std")] pub use crate::backend::BlockRef; +#[cfg(feature = "std")] pub use block_types::Block; +#[cfg(feature = "std")] pub use blocks_client::BlocksClient; pub use extrinsic_types::{ ExtrinsicDetails, ExtrinsicEvents, ExtrinsicSignedExtension, ExtrinsicSignedExtensions, diff --git a/subxt/src/client/mod.rs b/subxt/src/client/mod.rs index c764af4b59..ecd9a76502 100644 --- a/subxt/src/client/mod.rs +++ b/subxt/src/client/mod.rs @@ -9,6 +9,7 @@ //! access. mod offline_client; +#[cfg(feature = "std")] mod online_client; crate::macros::cfg_unstable_light_client! { @@ -20,6 +21,8 @@ crate::macros::cfg_unstable_light_client! { } pub use offline_client::{OfflineClient, OfflineClientT}; + +#[cfg(feature = "std")] 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 fc4ebf180c..6c81c667f0 100644 --- a/subxt/src/client/offline_client.rs +++ b/subxt/src/client/offline_client.rs @@ -11,7 +11,7 @@ use crate::{ use crate::prelude::*; use derivative::Derivative; -use std::sync::Arc; +use 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 80a5acb6bd..f4e2f8c723 100644 --- a/subxt/src/client/online_client.rs +++ b/subxt/src/client/online_client.rs @@ -4,7 +4,6 @@ use super::{OfflineClient, OfflineClientT}; use crate::custom_values::CustomValuesClient; -use crate::prelude::*; use crate::{ backend::{ legacy::LegacyBackend, rpc::RpcClient, Backend, BackendExt, RuntimeVersion, StreamOfResults, diff --git a/subxt/src/config/extrinsic_params.rs b/subxt/src/config/extrinsic_params.rs index 41b706a5df..567cd11f7d 100644 --- a/subxt/src/config/extrinsic_params.rs +++ b/subxt/src/config/extrinsic_params.rs @@ -33,6 +33,7 @@ pub enum ExtrinsicParamsError { UnknownSignedExtension(String), /// Some custom error. #[display(fmt = "Error constructing extrinsic parameters: {_0}")] + #[cfg(feature = "std")] Custom(CustomExtrinsicParamsError), } @@ -40,13 +41,17 @@ pub enum ExtrinsicParamsError { impl std::error::Error for ExtrinsicParamsError {} /// A custom error. +#[cfg(feature = "std")] pub type CustomExtrinsicParamsError = Box; -impl From for ExtrinsicParamsError { - fn from(value: std::convert::Infallible) -> Self { + +impl From for ExtrinsicParamsError { + fn from(value: core::convert::Infallible) -> Self { match value {} } } + +#[cfg(feature = "std")] impl From for ExtrinsicParamsError { fn from(value: CustomExtrinsicParamsError) -> Self { ExtrinsicParamsError::Custom(value) diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index 2b27577858..b555d7c8ad 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -76,7 +76,7 @@ pub trait BlockHash: + Encode + PartialEq + Eq - + std::hash::Hash + + core::hash::Hash { } impl BlockHash for T where @@ -91,7 +91,7 @@ impl BlockHash for T where + Encode + PartialEq + Eq - + std::hash::Hash + + core::hash::Hash { } diff --git a/subxt/src/config/signed_extensions.rs b/subxt/src/config/signed_extensions.rs index 5d3c10928b..5d720428e8 100644 --- a/subxt/src/config/signed_extensions.rs +++ b/subxt/src/config/signed_extensions.rs @@ -12,13 +12,12 @@ use crate::prelude::*; use crate::utils::Era; use crate::{client::OfflineClientT, Config}; use codec::{Compact, Encode}; +use collections::BTreeMap; use core::fmt::Debug; use derivative::Derivative; use scale_decode::DecodeAsType; use scale_info::PortableRegistry; -use std::collections::HashMap; - /// A single [`SignedExtension`] has a unique name, but is otherwise the /// same as [`ExtrinsicParams`] in describing how to encode the extra and /// additional data. @@ -393,7 +392,7 @@ macro_rules! impl_tuples { // For each signed extension in the tuple, find the matching index in the metadata, if // there is one, and add it to a map with that index as the key. - let mut exts_by_index = HashMap::new(); + let mut exts_by_index = BTreeMap::new(); $({ for (idx, e) in metadata.extrinsic().signed_extensions().iter().enumerate() { // Skip over any exts that have a match already: diff --git a/subxt/src/config/substrate.rs b/subxt/src/config/substrate.rs index 44cfcf7b73..8ea3f51012 100644 --- a/subxt/src/config/substrate.rs +++ b/subxt/src/config/substrate.rs @@ -5,11 +5,11 @@ //! Substrate specific configuration use super::{Config, DefaultExtrinsicParams, DefaultExtrinsicParamsBuilder, Hasher, Header}; -use codec::{Decode, Encode}; -use serde::{Deserialize, Serialize}; - +use crate::prelude::*; pub use crate::utils::{AccountId32, MultiAddress, MultiSignature}; +use codec::{Decode, Encode}; pub use primitive_types::{H256, U256}; +use serde::{Deserialize, Serialize}; /// 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 ba00db8c53..319900d13c 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::{dynamic::DecodedValueThunk, metadata::DecodeWithMetadata}; use derivative::Derivative; -use std::borrow::Cow; +use borrow::Cow; /// This represents a constant address. Anything implementing this trait /// can be used to fetch constants. diff --git a/subxt/src/custom_values/custom_values_client.rs b/subxt/src/custom_values/custom_values_client.rs index 9f193f394d..dcebb8fbb0 100644 --- a/subxt/src/custom_values/custom_values_client.rs +++ b/subxt/src/custom_values/custom_values_client.rs @@ -39,7 +39,7 @@ impl> CustomValuesClient { let custom = metadata.custom(); let custom_value = custom .get(address.name()) - .ok_or_else(|| MetadataError::CustomValueNameNotFound(address.name().to_string()))?; + .ok_or_else(|| MetadataError::CustomValueNameNotFound(address.name().to_owned()))?; let value = ::decode_with_metadata( &mut custom_value.bytes(), @@ -62,7 +62,7 @@ impl> CustomValuesClient { let custom = metadata.custom(); let custom_value = custom .get(address.name()) - .ok_or_else(|| MetadataError::CustomValueNameNotFound(address.name().to_string()))?; + .ok_or_else(|| MetadataError::CustomValueNameNotFound(address.name().to_owned()))?; Ok(custom_value.bytes().to_vec()) } diff --git a/subxt/src/error/dispatch_error.rs b/subxt/src/error/dispatch_error.rs index bada63c640..ae1e33bbae 100644 --- a/subxt/src/error/dispatch_error.rs +++ b/subxt/src/error/dispatch_error.rs @@ -10,7 +10,7 @@ use crate::prelude::*; use core::fmt::Debug; use derive_more::Display; use scale_decode::{visitor::DecodeAsTypeResult, DecodeAsType}; -use std::borrow::Cow; +use borrow::Cow; use super::{Error, MetadataError}; diff --git a/subxt/src/error/mod.rs b/subxt/src/error/mod.rs index c958ab8589..04756393ab 100644 --- a/subxt/src/error/mod.rs +++ b/subxt/src/error/mod.rs @@ -33,13 +33,13 @@ pub use subxt_metadata::TryFromError as MetadataTryFromError; #[non_exhaustive] pub enum Error { /// Io error. + #[cfg(feature = "std")] #[display(fmt = "Io error: {_0}")] Io(std::io::Error), /// Codec error. #[display(fmt = "Scale codec error: {_0}")] Codec(codec::Error), /// Rpc error. - #[cfg(feature = "std")] #[display(fmt = "Rpc error: {_0}")] Rpc(RpcError), /// Serde serialization error @@ -102,8 +102,8 @@ impl From for Error { } } -impl From for Error { - fn from(value: std::convert::Infallible) -> Self { +impl From for Error { + fn from(value: core::convert::Infallible) -> Self { match value {} } } @@ -111,13 +111,13 @@ impl From for Error { /// An RPC error. Since we are generic over the RPC client that is used, /// the error is boxed and could be casted. -#[cfg(feature = "std")] #[derive(Debug, Display)] #[non_exhaustive] pub enum RpcError { // Dev note: We need the error to be safely sent between threads // for `subscribe_to_block_headers_filling_in_gaps` and friends. /// Error related to the RPC client. + #[cfg(feature = "std")] #[display(fmt = "RPC error: {_0}")] ClientError(Box), /// This error signals that the request was rejected for some reason. diff --git a/subxt/src/events/events_client.rs b/subxt/src/events/events_client.rs index 8c8e8b489d..d991caad9d 100644 --- a/subxt/src/events/events_client.rs +++ b/subxt/src/events/events_client.rs @@ -2,11 +2,17 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::backend::{Backend, BackendExt, BlockRef}; use crate::prelude::*; -use crate::{client::OnlineClientT, error::Error, events::Events, Config}; +use crate::{error::Error, events::Events, Config}; use derivative::Derivative; -use std::future::Future; + +#[cfg(feature = "std")] +use crate::{ + backend::{Backend, BackendExt, BlockRef}, + client::OnlineClientT, +}; + +use core::future::Future; /// A client for working with events. #[derive(Derivative)] @@ -26,6 +32,7 @@ impl EventsClient { } } +#[cfg(feature = "std")] impl EventsClient where T: Config, @@ -86,6 +93,7 @@ fn system_events_key() -> [u8; 32] { } // Get the event bytes from the provided client, at the provided block hash. +#[cfg(feature = "std")] pub(crate) async fn get_event_bytes( backend: &dyn Backend, block_hash: T::Hash, diff --git a/subxt/src/events/events_type.rs b/subxt/src/events/events_type.rs index 5f94a4f766..f04274122f 100644 --- a/subxt/src/events/events_type.rs +++ b/subxt/src/events/events_type.rs @@ -5,18 +5,20 @@ //! A representation of a block of events. use super::{Phase, StaticEvent}; +use crate::prelude::*; use crate::{ - client::OnlineClientT, error::{Error, MetadataError}, - events::events_client::get_event_bytes, metadata::types::PalletMetadata, Config, Metadata, }; -use crate::prelude::*; + +#[cfg(feature = "std")] +use crate::{client::OnlineClientT, events::events_client::get_event_bytes}; + use codec::{Compact, Decode}; use derivative::Derivative; use scale_decode::DecodeAsType; -use std::sync::Arc; +use sync::Arc; /// A collection of events obtained from a block, bundled with the necessary /// information needed to decode and iterate over them. @@ -34,8 +36,8 @@ pub struct Events { } // Ignore the Metadata when debug-logging events; it's big and distracting. -impl std::fmt::Debug for Events { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Events { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("Events") .field("block_hash", &self.block_hash) .field("event_bytes", &self.event_bytes) @@ -77,6 +79,7 @@ impl Events { /// latest metadata version. /// - The client may not be able to obtain the block at the given hash. Only /// archive nodes keep hold of all past block information. + #[cfg(feature = "std")] pub async fn new_from_client( metadata: Metadata, block_hash: T::Hash, @@ -120,7 +123,7 @@ impl Events { let mut pos = self.start_idx; let mut index = 0; - std::iter::from_fn(move || { + core::iter::from_fn(move || { if event_bytes.len() <= pos || num_events == index { None } else { diff --git a/subxt/src/lib.rs b/subxt/src/lib.rs index b3ddbb3666..5884649c91 100644 --- a/subxt/src/lib.rs +++ b/subxt/src/lib.rs @@ -43,6 +43,7 @@ use tracing_subscriber as _; #[allow(unused_imports)] pub use getrandom as _; +#[cfg(feature = "std")] pub mod backend; pub mod blocks; pub mod client; @@ -53,11 +54,11 @@ pub mod dynamic; pub mod error; pub mod events; pub mod metadata; +pub mod prelude; pub mod runtime_api; pub mod storage; pub mod tx; pub mod utils; -pub mod prelude; // Internal helper macros #[macro_use] @@ -66,12 +67,15 @@ mod macros; // Expose a few of the most common types at root, // but leave most types behind their respective modules. pub use crate::{ - client::{OfflineClient, OnlineClient}, + client::OfflineClient, config::{Config, PolkadotConfig, SubstrateConfig}, error::Error, metadata::Metadata, }; +#[cfg(feature = "std")] +pub use crate::client::OnlineClient; + /// Re-export external crates that are made use of in the subxt API. pub mod ext { pub use codec; diff --git a/subxt/src/metadata/metadata_type.rs b/subxt/src/metadata/metadata_type.rs index 9f21d78a71..150bcd69a5 100644 --- a/subxt/src/metadata/metadata_type.rs +++ b/subxt/src/metadata/metadata_type.rs @@ -4,7 +4,7 @@ use crate::error::MetadataError; use crate::prelude::*; -use std::sync::Arc; +use sync::Arc; /// A cheaply clone-able representation of the runtime metadata received from a node. #[derive(Clone, Debug)] @@ -12,7 +12,7 @@ pub struct Metadata { inner: Arc, } -impl std::ops::Deref for Metadata { +impl core::ops::Deref for Metadata { type Target = subxt_metadata::Metadata; fn deref(&self) -> &Self::Target { &self.inner diff --git a/subxt/src/prelude.rs b/subxt/src/prelude.rs index 2bd5855fd2..47b60ab47c 100644 --- a/subxt/src/prelude.rs +++ b/subxt/src/prelude.rs @@ -16,6 +16,7 @@ cfg_if! { pub use std::{ any, borrow, + borrow::ToOwned, boxed::{Box}, cmp, collections, @@ -29,8 +30,8 @@ cfg_if! { string::{String}, str, sync, - time, vec, + time, rc, iter, }; @@ -38,15 +39,16 @@ cfg_if! { } else { pub use alloc::{ borrow, + borrow::ToOwned, boxed::{Box}, collections, format, string::{String}, sync, - vec::{Vec}, + vec, rc, }; - pub use std::vec::Vec; + pub use alloc::vec::Vec; pub use core::{ any, cmp, diff --git a/subxt/src/runtime_api/mod.rs b/subxt/src/runtime_api/mod.rs index 49a17a4dd7..6a62b6c7f5 100644 --- a/subxt/src/runtime_api/mod.rs +++ b/subxt/src/runtime_api/mod.rs @@ -4,10 +4,18 @@ //! Types associated with executing runtime API calls. +#[cfg(feature = "std")] mod runtime_client; + mod runtime_payload; +#[cfg(feature = "std")] mod runtime_types; + +#[cfg(feature = "std")] pub use runtime_client::RuntimeApiClient; + pub use runtime_payload::{dynamic, DynamicRuntimeApiPayload, Payload, RuntimeApiPayload}; + +#[cfg(feature = "std")] pub use runtime_types::RuntimeApi; diff --git a/subxt/src/runtime_api/runtime_client.rs b/subxt/src/runtime_api/runtime_client.rs index 19c4d583a4..0fa0aab5ce 100644 --- a/subxt/src/runtime_api/runtime_client.rs +++ b/subxt/src/runtime_api/runtime_client.rs @@ -4,11 +4,13 @@ use super::runtime_types::RuntimeApi; -use crate::{backend::BlockRef, client::OnlineClientT, error::Error, Config}; -use crate::prelude::*; +use crate::{error::Error, Config}; use derivative::Derivative; use std::{future::Future, marker::PhantomData}; +#[cfg(feature = "std")] +use crate::{backend::BlockRef, client::OnlineClientT}; + /// Execute runtime API calls. #[derive(Derivative)] #[derivative(Clone(bound = "Client: Clone"))] @@ -27,6 +29,7 @@ impl RuntimeApiClient { } } +#[cfg(feature = "std")] impl RuntimeApiClient where T: Config, diff --git a/subxt/src/runtime_api/runtime_payload.rs b/subxt/src/runtime_api/runtime_payload.rs index 8e79c0a9cb..9dc8120590 100644 --- a/subxt/src/runtime_api/runtime_payload.rs +++ b/subxt/src/runtime_api/runtime_payload.rs @@ -5,7 +5,8 @@ use derivative::Derivative; use scale_encode::EncodeAsFields; use scale_value::Composite; -use std::borrow::Cow; +use crate::prelude::*; +use borrow::Cow; use crate::dynamic::DecodedValueThunk; use crate::error::MetadataError; @@ -69,7 +70,7 @@ pub trait RuntimeApiPayload { #[derive(Derivative)] #[derivative( Clone(bound = "ArgsData: Clone"), - Debug(bound = "ArgsData: std::fmt::Debug") + Debug(bound = "ArgsData: core::fmt::Debug") )] pub struct Payload { trait_name: Cow<'static, str>, diff --git a/subxt/src/runtime_api/runtime_types.rs b/subxt/src/runtime_api/runtime_types.rs index da4d45ce11..629cdb2dee 100644 --- a/subxt/src/runtime_api/runtime_types.rs +++ b/subxt/src/runtime_api/runtime_types.rs @@ -3,12 +3,18 @@ // see LICENSE for license details. use crate::{ - backend::{BackendExt, BlockRef}, - client::OnlineClientT, + error::{Error, MetadataError}, metadata::DecodeWithMetadata, Config, }; + +#[cfg(feature = "std")] +use crate::{ + backend::{BackendExt, BlockRef}, + client::OnlineClientT, +} + use crate::prelude::*; use codec::Decode; use derivative::Derivative; @@ -36,6 +42,7 @@ impl RuntimeApi { } } +#[cfg(feature = "std")] impl RuntimeApi where T: Config, diff --git a/subxt/src/storage/mod.rs b/subxt/src/storage/mod.rs index 0219cd8caf..c0b0f5bd13 100644 --- a/subxt/src/storage/mod.rs +++ b/subxt/src/storage/mod.rs @@ -6,12 +6,15 @@ mod storage_address; mod storage_client; + +#[cfg(feature = "std")] mod storage_type; pub mod utils; pub use storage_client::StorageClient; +#[cfg(feature = "std")] pub use storage_type::Storage; /// Types representing an address which describes where a storage diff --git a/subxt/src/storage/storage_address.rs b/subxt/src/storage/storage_address.rs index 3973251636..60f9b0d903 100644 --- a/subxt/src/storage/storage_address.rs +++ b/subxt/src/storage/storage_address.rs @@ -11,7 +11,7 @@ use crate::{ }; use derivative::Derivative; use scale_info::TypeDef; -use std::borrow::Cow; +use borrow::Cow; use subxt_metadata::{StorageEntryType, StorageHasher}; /// This represents a storage address. Anything implementing this trait @@ -56,7 +56,7 @@ 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>, diff --git a/subxt/src/storage/storage_client.rs b/subxt/src/storage/storage_client.rs index 204ab9fcb0..2f13466cb0 100644 --- a/subxt/src/storage/storage_client.rs +++ b/subxt/src/storage/storage_client.rs @@ -2,19 +2,19 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use super::{ - storage_type::{validate_storage_address, Storage}, - utils, StorageAddress, -}; +use super::{utils, StorageAddress}; +use crate::prelude::*; +use crate::{client::OfflineClientT, error::Error, Config}; + +#[cfg(feature = "std")] use crate::{ backend::BlockRef, - client::{OfflineClientT, OnlineClientT}, - error::Error, - Config, + client::OnlineClientT, + storage::storage_type::{validate_storage_address, Storage}, }; -use crate::prelude::*; + +use core::{future::Future, marker::PhantomData}; use derivative::Derivative; -use std::{future::Future, marker::PhantomData}; /// Query the runtime storage. #[derive(Derivative)] @@ -68,6 +68,7 @@ where } } +#[cfg(feature = "std")] impl StorageClient where T: Config, diff --git a/subxt/src/storage/storage_type.rs b/subxt/src/storage/storage_type.rs index 74538c854f..e7e2e906ca 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; diff --git a/subxt/src/tx/mod.rs b/subxt/src/tx/mod.rs index 0bb2d9f3eb..89bf483258 100644 --- a/subxt/src/tx/mod.rs +++ b/subxt/src/tx/mod.rs @@ -14,6 +14,8 @@ use crate::macros::cfg_substrate_compat; mod signer; mod tx_client; mod tx_payload; + +#[cfg(feature = "std")] mod tx_progress; // The PairSigner impl currently relies on Substrate bits and pieces, so make it an optional @@ -29,5 +31,7 @@ pub use self::{ ValidationResult, }, tx_payload::{dynamic, BoxedPayload, DynamicPayload, Payload, TxPayload}, - tx_progress::{TxInBlock, TxProgress, TxStatus}, }; + +#[cfg(feature = "std")] +pub use self::tx_progress::{TxInBlock, TxProgress, TxStatus}; diff --git a/subxt/src/tx/tx_client.rs b/subxt/src/tx/tx_client.rs index cb569e9ffd..7b126bf428 100644 --- a/subxt/src/tx/tx_client.rs +++ b/subxt/src/tx/tx_client.rs @@ -2,18 +2,24 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use std::borrow::Cow; - use crate::prelude::*; +use borrow::Cow; + +#[cfg(feature = "std")] use crate::{ backend::{BackendExt, BlockRef, TransactionStatus}, - client::{OfflineClientT, OnlineClientT}, + client::OnlineClientT, + tx::TxProgress, +}; +use crate::{ + client::OfflineClientT, config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder, Hasher}, error::{Error, MetadataError}, prelude::*, - tx::{Signer as SignerT, TxPayload, TxProgress}, + tx::{Signer as SignerT, TxPayload}, utils::{Encoded, PhantomDataSendSync}, }; + use codec::{Compact, Decode, Encode}; use derivative::Derivative; use sp_core_hashing::blake2_256; @@ -162,6 +168,7 @@ impl> TxClient { } } +#[cfg(feature = "std")] impl TxClient where T: Config, @@ -426,6 +433,7 @@ where } } +#[cfg(feature = "std")] impl SubmittableExtrinsic where T: Config, diff --git a/subxt/src/tx/tx_payload.rs b/subxt/src/tx/tx_payload.rs index 76ee693123..a8d7005383 100644 --- a/subxt/src/tx/tx_payload.rs +++ b/subxt/src/tx/tx_payload.rs @@ -5,16 +5,16 @@ //! This module contains the trait and types used to represent //! transactions that can be submitted. +use crate::prelude::*; +use crate::prelude::{borrow::Cow, sync::Arc}; use crate::{ dynamic::Value, error::{Error, MetadataError}, metadata::Metadata, }; -use crate::prelude::*; use codec::Encode; use scale_encode::EncodeAsFields; use scale_value::{Composite, ValueDef, Variant}; -use std::{borrow::Cow, sync::Arc}; /// 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 2616f009bd..d8f0c1fe2a 100644 --- a/subxt/src/tx/tx_progress.rs +++ b/subxt/src/tx/tx_progress.rs @@ -4,7 +4,6 @@ //! Types representing extrinsics/transactions that have been submitted to a node. -use crate::prelude::*; use crate::utils::strip_compact_prefix; use crate::{ backend::{BlockRef, StreamOfResults, TransactionStatus as BackendTxStatus}, @@ -24,8 +23,8 @@ pub struct TxProgress { client: C, } -impl fmt::Debug for TxProgress { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl std::fmt::Debug for TxProgress { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("TxProgress") .field("sub", &"") .field("ext_hash", &self.ext_hash) @@ -168,7 +167,7 @@ impl Stream for TxProgress { /// Possible transaction statuses returned from our [`TxProgress::next()`] call. #[derive(Derivative)] -#[derivative(Debug(bound = "C: fmt::Debug"))] +#[derivative(Debug(bound = "C: std::fmt::Debug"))] pub enum TxStatus { /// Transaction is part of the future queue. Validated, @@ -222,7 +221,7 @@ impl TxStatus { /// This struct represents a transaction that has made it into a block. #[derive(Derivative)] -#[derivative(Debug(bound = "C: fmt::Debug"))] +#[derivative(Debug(bound = "C: std::fmt::Debug"))] pub struct TxInBlock { block_ref: BlockRef, ext_hash: T::Hash, diff --git a/subxt/src/utils/account_id.rs b/subxt/src/utils/account_id.rs index 907257e471..2a4e5f4be7 100644 --- a/subxt/src/utils/account_id.rs +++ b/subxt/src/utils/account_id.rs @@ -6,6 +6,7 @@ //! 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::vec; use crate::prelude::*; use codec::{Decode, Encode}; use derive_more::Display; diff --git a/subxt/src/utils/mod.rs b/subxt/src/utils/mod.rs index 95fd1ad64e..e6c09c31ce 100644 --- a/subxt/src/utils/mod.rs +++ b/subxt/src/utils/mod.rs @@ -55,7 +55,7 @@ pub(crate) fn strip_compact_prefix(bytes: &[u8]) -> Result<(u64, &[u8]), codec:: /// /// Returns an error if the the string could not be parsed into a URL. pub fn url_is_secure(url: &str) -> Result { - let url = Url::parse(url).map_err(|e| Error::Rpc(RpcError::ClientError(Box::new(e))))?; + let url = Url::parse(url).map_err(|e| Error::Rpc(RpcError::InsecureUrl(url.to_owned())))?; let secure_scheme = url.scheme() == "https" || url.scheme() == "wss"; let is_localhost = url.host().is_some_and(|e| match e {