Skip to content

Commit

Permalink
Merge branch 'master' into wgyt-subxt-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 authored Feb 24, 2025
2 parents f3ef5fb + 69ce6d7 commit bab4c97
Show file tree
Hide file tree
Showing 29 changed files with 338 additions and 5,899 deletions.
6,124 changes: 286 additions & 5,838 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ web-time = { version = "1.1", default-features = false }
tokio-util = "0.7.12"

# Substrate crates:
polkadot-sdk = { version = "0.7", default-features = false }
sc-executor = { version = "0.41.0", default-features = false }
sc-executor-common = { version = "0.36.0", default-features = false }
sp-crypto-hashing = { version = "0.1.0", default-features = false }
sp-core = { version = "35.0.0", default-features = false }
sp-keyring = { version = "40.0.0", default-features = false }
sp-maybe-compressed-blob = { version = "11.0.0", default-features = false }
sp-io = { version = "39.0.0", default-features = false }
sp-state-machine = { version = "0.44.0", default-features = false }
sp-runtime = { version = "40.0.1", default-features = false }

# Subxt workspace crates:
subxt = { version = "0.39.0", path = "subxt", default-features = false }
Expand Down
7 changes: 4 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ std = [
"tracing/std",
"impl-serde/std",
"primitive-types/std",
"sp-crypto-hashing/std",
]

[dependencies]
Expand All @@ -44,11 +45,10 @@ hex = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde_json = { workspace = true, default-features = false, features = ["raw_value", "alloc"] }
tracing = { workspace = true, default-features = false }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing"] }
sp-crypto-hashing = { workspace = true }
hashbrown = { workspace = true }
thiserror = { workspace = true, default-features = false }


# For ss58 encoding AccountId32 to serialize them properly:
base58 = { workspace = true }
blake2 = { workspace = true }
Expand All @@ -66,7 +66,8 @@ bitvec = { workspace = true }
codec = { workspace = true, features = ["derive", "bit-vec"] }
subxt-macro = { workspace = true }
subxt-signer = { workspace = true, features = ["sr25519", "subxt"] }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing", "sp-core", "sp-keyring"] }
sp-core = { workspace = true }
sp-keyring = { workspace = true }
hex = { workspace = true }

[package.metadata.docs.rs]
Expand Down
6 changes: 2 additions & 4 deletions core/src/config/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
//! Substrate specific configuration
use super::{Config, DefaultExtrinsicParams, DefaultExtrinsicParamsBuilder, Hasher, Header};
pub use crate::utils::{AccountId32, MultiAddress, MultiSignature};
use alloc::format;
use alloc::vec::Vec;
use codec::{Decode, Encode};
use polkadot_sdk::sp_crypto_hashing;
use serde::{Deserialize, Serialize};

pub use crate::utils::{AccountId32, MultiAddress, MultiSignature};
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
Expand Down
6 changes: 2 additions & 4 deletions core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ impl<T: Config> Events<T> {
/// them, and return only those which should decode to the provided `Ev` type.
/// If an error occurs, all subsequent iterations return `None`.
pub fn find<Ev: StaticEvent>(&self) -> impl Iterator<Item = Result<Ev, Error>> + '_ {
self.iter().filter_map(|ev| {
ev.and_then(|ev| ev.as_event::<Ev>().map_err(Into::into))
.transpose()
})
self.iter()
.filter_map(|ev| ev.and_then(|ev| ev.as_event::<Ev>()).transpose())
}

/// Iterate through the events using metadata to dynamically decode and skip
Expand Down
1 change: 0 additions & 1 deletion core/src/storage/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::error::{Error, MetadataError};
use crate::metadata::Metadata;
use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use polkadot_sdk::sp_crypto_hashing;
use subxt_metadata::{PalletMetadata, StorageEntryMetadata, StorageHasher};

/// Return the root of a given [`Address`]: hash the pallet name and entry name
Expand Down
2 changes: 1 addition & 1 deletion core/src/tx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ use alloc::borrow::{Cow, ToOwned};
use alloc::vec::Vec;
use codec::{Compact, Encode};
use payload::Payload;
use polkadot_sdk::sp_crypto_hashing::blake2_256;
use signer::Signer as SignerT;
use sp_crypto_hashing::blake2_256;

// Expose these here since we expect them in some calls below.
pub use crate::client::{ClientState, RuntimeVersion};
Expand Down
4 changes: 2 additions & 2 deletions core/src/utils/account_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ impl core::str::FromStr for AccountId32 {
#[cfg(test)]
mod test {
use super::*;
use polkadot_sdk::sp_core::{self, crypto::Ss58Codec};
use polkadot_sdk::sp_keyring::AccountKeyring;
use sp_core::{self, crypto::Ss58Codec};
use sp_keyring::AccountKeyring;

#[test]
fn ss58_is_compatible_with_substrate_impl() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/utils/account_id20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl AccountId20 {

for (i, ch) in hex_address.chars().enumerate() {
// Get the corresponding nibble from the hash
let nibble = hash[i / 2] >> (if i % 2 == 0 { 4 } else { 0 }) & 0xf;
let nibble = (hash[i / 2] >> (if i % 2 == 0 { 4 } else { 0 })) & 0xf;

if nibble >= 8 {
checksum_address.push(ch.to_ascii_uppercase());
Expand Down
8 changes: 6 additions & 2 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ description = "Generate types and helpers for interacting with Substrate runtime

[features]
web = ["subxt-codegen/web"]
runtime-metadata-path = ["polkadot-sdk"]
runtime-metadata-path = ["sc-executor", "sc-executor-common", "sp-maybe-compressed-blob", "sp-io", "sp-state-machine"]
runtime-metadata-insecure-url = ["subxt-utils-fetchmetadata/url"]

[lib]
Expand All @@ -30,7 +30,11 @@ quote = { workspace = true }
subxt-codegen = { workspace = true }
subxt-utils-fetchmetadata = { workspace = true }
scale-typegen = { workspace = true }
polkadot-sdk = { workspace = true, optional = true, features = ["sp-io", "sc-executor-common", "sp-state-machine", "sp-maybe-compressed-blob", "sc-executor"] }
sc-executor = { workspace = true, optional = true }
sc-executor-common = { workspace = true, optional = true }
sp-maybe-compressed-blob = { workspace = true, optional = true }
sp-io = { workspace = true, optional = true }
sp-state-machine = { workspace = true, optional = true }

[lints]
workspace = true
10 changes: 3 additions & 7 deletions macro/src/wasm_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
use std::{borrow::Cow, path::Path};

use codec::{Decode, Encode};
use polkadot_sdk::{
sc_executor::{self, WasmExecutionMethod, WasmExecutor},
sc_executor_common::runtime_blob::RuntimeBlob,
sp_io,
sp_maybe_compressed_blob::{self, CODE_BLOB_BOMB_LIMIT},
sp_state_machine,
};
use sc_executor::{WasmExecutionMethod, WasmExecutor};
use sc_executor_common::runtime_blob::RuntimeBlob;
use sp_maybe_compressed_blob::{self, CODE_BLOB_BOMB_LIMIT};
use subxt_codegen::{CodegenError, Metadata};

static SUPPORTED_METADATA_VERSIONS: [u32; 2] = [14, 15];
Expand Down
2 changes: 1 addition & 1 deletion metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ scale-info = { workspace = true, default-features = false }
frame-decode = { workspace = true }
frame-metadata = { workspace = true, default-features = false, features = ["current", "decode"] }
codec = { package = "parity-scale-codec", workspace = true, default-features = false, features = ["derive"] }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing"] }
sp-crypto-hashing = { workspace = true }
hashbrown = { workspace = true }
thiserror = { workspace = true, default-features = false }

Expand Down
1 change: 0 additions & 1 deletion metadata/src/utils/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
use alloc::vec::Vec;
use hashbrown::HashMap;
use outer_enum_hashes::OuterEnumHashes;
use polkadot_sdk::sp_crypto_hashing;
use scale_info::{form::PortableForm, Field, PortableRegistry, TypeDef, TypeDefVariant, Variant};

pub mod outer_enum_hashes;
Expand Down
10 changes: 2 additions & 8 deletions rpcs/src/methods/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ impl<T: RpcConfig> LegacyRpcMethods<T> {
) -> Result<Vec<StorageChangeSet<T::Hash>>, Error> {
let keys: Vec<String> = keys.into_iter().map(to_hex).collect();
let params = rpc_params![keys, from, to];
self.client
.request("state_queryStorage", params)
.await
.map_err(Into::into)
self.client.request("state_queryStorage", params).await
}

/// Query storage entries at some block, using the best block if none is given.
Expand All @@ -85,10 +82,7 @@ impl<T: RpcConfig> LegacyRpcMethods<T> {
) -> Result<Vec<StorageChangeSet<T::Hash>>, Error> {
let keys: Vec<String> = keys.into_iter().map(to_hex).collect();
let params = rpc_params![keys, at];
self.client
.request("state_queryStorageAt", params)
.await
.map_err(Into::into)
self.client.request("state_queryStorageAt", params).await
}

/// Fetch the genesis hash
Expand Down
5 changes: 3 additions & 2 deletions signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cfg-if = { workspace = true }
codec = { package = "parity-scale-codec", workspace = true, features = [
"derive",
] }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing"] }
sp-crypto-hashing = { workspace = true }
pbkdf2 = { workspace = true }
sha2 = { workspace = true }
hmac = { workspace = true }
Expand Down Expand Up @@ -87,7 +87,8 @@ getrandom = { workspace = true, optional = true }
[dev-dependencies]
proptest = { workspace = true }
hex-literal = { workspace = true }
polkadot-sdk = { workspace = true, features = ["sp-core", "sp-keyring"] }
sp-core = { workspace = true }
sp-keyring = { workspace = true }

[package.metadata.cargo-machete]
ignored = ["getrandom"]
Expand Down
1 change: 0 additions & 1 deletion signer/src/crypto/derive_junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// see LICENSE for license details.

use codec::{Decode, Encode};
use polkadot_sdk::sp_crypto_hashing;

// This code is taken from sp_core::crypto::DeriveJunction. The logic should be identical,
// though the API is tweaked a touch.
Expand Down
3 changes: 1 addition & 2 deletions signer/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use codec::Encode;
use crate::crypto::{seed_from_entropy, DeriveJunction, SecretUri};
use core::str::FromStr;
use hex::FromHex;
use polkadot_sdk::sp_crypto_hashing;
use secp256k1::{ecdsa::RecoverableSignature, Message, Secp256k1, SecretKey};
use secrecy::ExposeSecret;

Expand Down Expand Up @@ -362,7 +361,7 @@ mod test {

use super::*;

use polkadot_sdk::sp_core::{self, crypto::Pair as _, ecdsa::Pair as SpPair};
use sp_core::{self, crypto::Pair as _, ecdsa::Pair as SpPair};

#[test]
fn check_from_phrase_matches() {
Expand Down
3 changes: 1 addition & 2 deletions signer/src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ mod test {

use super::*;

use polkadot_sdk::sp_core::{self, crypto::Pair as _, sr25519::Pair as SpPair};
use polkadot_sdk::sp_keyring;
use sp_core::{self, crypto::Pair as _, sr25519::Pair as SpPair};

#[test]
fn check_from_phrase_matches() {
Expand Down
8 changes: 5 additions & 3 deletions subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ native = [
"subxt-rpcs/native",
"tokio-util",
"tokio?/sync",
"polkadot-sdk/std",
"sp-crypto-hashing/std",
]

# Enable this for web/wasm builds.
Expand Down Expand Up @@ -86,7 +86,7 @@ futures = { workspace = true }
hex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["default", "raw_value"] }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing"] }
sp-crypto-hashing = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
frame-metadata = { workspace = true }
Expand Down Expand Up @@ -123,7 +123,9 @@ bitvec = { workspace = true }
codec = { workspace = true, features = ["derive", "bit-vec"] }
scale-info = { workspace = true, features = ["bit-vec"] }
tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread", "sync"] }
polkadot-sdk = { workspace = true, features = ["sp-core", "sp-keyring", "sp-runtime", "std"] }
sp-core = { workspace = true, features = ["std"] }
sp-keyring = { workspace = true, features = ["std"] }
sp-runtime = { workspace = true, features = ["std"] }
assert_matches = { workspace = true }
subxt-signer = { path = "../signer", features = ["unstable-eth"] }
subxt-rpcs = { workspace = true, features = ["subxt", "mock-rpc-client"] }
Expand Down
6 changes: 3 additions & 3 deletions subxt/examples/substrate_compat_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#![allow(missing_docs, unused)]

use polkadot_sdk::sp_core::{sr25519, Pair as _};
use sp_core::{sr25519, Pair as _};
use subxt::config::substrate::MultiAddress;
use subxt::{Config, OnlineClient, PolkadotConfig};

Expand All @@ -17,7 +17,7 @@ pub mod polkadot {}
/// and that PolkadotConfig is the runtime configuration.
mod pair_signer {
use super::*;
use polkadot_sdk::sp_runtime::{
use sp_runtime::{
traits::{IdentifyAccount, Verify},
MultiSignature as SpMultiSignature,
};
Expand All @@ -26,7 +26,7 @@ mod pair_signer {
tx::Signer,
};

/// A [`Signer`] implementation for [`polkadot_sdk::sp_core::sr25519::Pair`].
/// A [`Signer`] implementation for [`sp_core::sr25519::Pair`].
#[derive(Clone)]
pub struct PairSigner {
account_id: <PolkadotConfig as Config>::AccountId,
Expand Down
1 change: 0 additions & 1 deletion subxt/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ mod test {
use crate::backend::StorageResponse;
use core::convert::Infallible;
use futures::StreamExt;
use polkadot_sdk::sp_core;
use primitive_types::H256;
use rpc::RpcClientT;
use std::collections::{HashMap, VecDeque};
Expand Down
1 change: 0 additions & 1 deletion subxt/src/events/events_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use crate::backend::{Backend, BackendExt, BlockRef};
use crate::{client::OnlineClientT, error::Error, events::Events, Config};
use derive_where::derive_where;
use polkadot_sdk::sp_crypto_hashing;
use std::future::Future;

/// A client for working with events.
Expand Down
2 changes: 1 addition & 1 deletion subxt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub mod ext {
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// substitute_type(
/// path = "sp_runtime::multiaddress::MultiAddress<A, B>",
/// with = "::subxt::utils::Static<polkadot_sdk::sp_runtime::MultiAddress<A, B>>"
/// with = "::subxt::utils::Static<sp_runtime::MultiAddress<A, B>>"
/// )
/// )]
/// mod polkadot {}
Expand Down
1 change: 0 additions & 1 deletion subxt/src/storage/storage_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
use codec::Decode;
use derive_where::derive_where;
use futures::StreamExt;
use polkadot_sdk::sp_crypto_hashing;
use std::{future::Future, marker::PhantomData};
use subxt_core::storage::address::{Address, StorageHashers, StorageKey};
use subxt_core::utils::Yes;
Expand Down
4 changes: 2 additions & 2 deletions subxt/src/tx/tx_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ mod test {

#[test]
fn transaction_validity_decoding_is_ok() {
use polkadot_sdk::sp_runtime::transaction_validity as sp;
use polkadot_sdk::sp_runtime::transaction_validity::TransactionValidity as T;
use sp_runtime::transaction_validity as sp;
use sp_runtime::transaction_validity::TransactionValidity as T;

let pairs = vec![
(
Expand Down
2 changes: 1 addition & 1 deletion testing/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ hex = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
scale-info = { workspace = true, features = ["bit-vec"] }
polkadot-sdk = { workspace = true, features = ["sp-core", "std"] }
sp-core = { workspace = true, features = ["std"] }
syn = { workspace = true }
subxt = { workspace = true, features = ["unstable-metadata", "native", "jsonrpsee", "reconnecting-rpc-client"] }
subxt-signer = { workspace = true, features = ["default"] }
Expand Down
1 change: 0 additions & 1 deletion testing/integration-tests/src/full_client/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// see LICENSE for license details.

use crate::{node_runtime, subxt_test, test_context, utils::wait_for_blocks};
use polkadot_sdk::sp_core;

#[cfg(fullclient)]
use subxt::utils::AccountId32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ error: Type `Event` does not exist at path `sp_runtime::multiaddress::Event`
2 | | runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
3 | | substitute_type(
4 | | path = "sp_runtime::multiaddress::Event",
5 | | with = "crate::MyEvent"
6 | | )
... |
7 | | )]
| |__^
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ error: Type `DispatchInfo` does not exist at path `frame_support::dispatch::Disp
2 | | runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
3 | | substitute_type(
4 | | path = "frame_support::dispatch::DispatchInfo",
5 | | with = "my_mod::DispatchInfo"
6 | | )
... |
7 | | )]
| |__^
|
Expand Down

0 comments on commit bab4c97

Please sign in to comment.