Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sp_core and sp_runtime dependencies optional, and bump to latest #760

Merged
merged 28 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
948f88d
begin porting over traits; remove Config use of Hash
jsdw Jan 4, 2023
b8912be
port over the Header bits that we need
jsdw Jan 4, 2023
c1f0779
sp_core_hashing where possible, move Verify to PairSigner, remove unu…
jsdw Jan 4, 2023
e7d23b2
tidy up Config things and move related bits into one place
jsdw Jan 5, 2023
5d4f168
fix codegen
jsdw Jan 5, 2023
801fbe6
copy Era over
jsdw Jan 5, 2023
1a0f4e8
move AccountId, Address, Signer to Signer trait and a pass over fixin…
jsdw Jan 5, 2023
7df5ae1
impl MultiAddress, MultiSignature, AccountId32 and add back to Config…
jsdw Jan 5, 2023
8eac9f2
Copy over StorageKey, StorageData, StorageChangeSet
jsdw Jan 5, 2023
7b91522
subxt core compiling with no sp_core or sp_runtime
jsdw Jan 6, 2023
22d2259
Get examples compiling
jsdw Jan 6, 2023
7c283e7
pass over fixing tests
jsdw Jan 6, 2023
5776669
cargo fmt
jsdw Jan 6, 2023
cf7561e
clippy tweaks and update polkadot.rs
jsdw Jan 6, 2023
7192cec
fix codegen docs
jsdw Jan 6, 2023
2c9838e
port over special DigestItem encoding/decoding
jsdw Jan 6, 2023
8d6685e
clippy and doc fixes
jsdw Jan 6, 2023
ec53f2d
cargo fmt and example fix
jsdw Jan 6, 2023
a6b451a
more cargo fmt-ing...
jsdw Jan 6, 2023
de1e7d7
substrate-extra to substrate-compat
jsdw Jan 6, 2023
093f129
cargo.toml comments
jsdw Jan 6, 2023
84cf950
simplify PairSigner trait bounds
jsdw Jan 6, 2023
6696003
move RPC types to a separate file
jsdw Jan 9, 2023
799abbd
fix docs
jsdw Jan 9, 2023
fa88846
Add some tests for things and other PR feedback
jsdw Jan 9, 2023
7359b80
Merge branch 'master' into jsdw-remove-substrate-deps
jsdw Jan 10, 2023
fa7913b
bump to latest sp deps
jsdw Jan 10, 2023
df703ee
avoid needing substrate-compat feature in a test
jsdw Jan 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions codegen/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,23 @@ impl RuntimeGenerator {
),
(
"sp_core::crypto::AccountId32",
parse_quote!(#crate_path::ext::sp_core::crypto::AccountId32),
parse_quote!(#crate_path::utils::account_id::AccountId32),
jsdw marked this conversation as resolved.
Show resolved Hide resolved
),
(
"sp_runtime::multiaddress::MultiAddress",
parse_quote!(#crate_path::utils::multi_address::MultiAddress),
),
(
"primitive_types::H160",
parse_quote!(#crate_path::ext::sp_core::H160),
parse_quote!(#crate_path::utils::H160),
),
(
"primitive_types::H256",
parse_quote!(#crate_path::ext::sp_core::H256),
parse_quote!(#crate_path::utils::H256),
),
(
"primitive_types::H512",
parse_quote!(#crate_path::ext::sp_core::H512),
),
(
"sp_runtime::multiaddress::MultiAddress",
parse_quote!(#crate_path::ext::sp_runtime::MultiAddress),
parse_quote!(#crate_path::utils::H512),
),
(
"frame_support::traits::misc::WrapperKeepOpaque",
Expand Down
4 changes: 3 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ description = "Subxt example usage"
[dev-dependencies]
subxt = { path = "../subxt" }
tokio = { version = "1.8", features = ["rt-multi-thread", "macros", "time"] }
sp-keyring = "7.0.0"
sp-keyring = "11.0.0"
futures = "0.3.13"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
hex = "0.4.3"
tracing-subscriber = "0.3.11"
sp-core = { version = "10.0.0", default-features = false }
sp-runtime = { version = "11.0.0" }
jsdw marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 8 additions & 6 deletions examples/examples/balance_transfer_with_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@

use sp_keyring::AccountKeyring;
use subxt::{
tx::{
Era,
PairSigner,
PlainTip,
PolkadotExtrinsicParamsBuilder as Params,
config::{
polkadot::{
Era,
PlainTip,
PolkadotExtrinsicParamsBuilder as Params,
},
PolkadotConfig,
},
tx::PairSigner,
OnlineClient,
PolkadotConfig,
};

#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/concurrent_storage_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod polkadot {}
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api = OnlineClient::<PolkadotConfig>::new().await?;

let addr = AccountKeyring::Bob.to_account_id();
let addr = AccountKeyring::Bob.to_account_id().into();

// Construct storage addresses to access:
let staking_bonded = polkadot::storage().staking().bonded(&addr);
Expand Down
10 changes: 4 additions & 6 deletions examples/examples/custom_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
use sp_keyring::AccountKeyring;
use subxt::{
config::{
substrate::SubstrateExtrinsicParams,
Config,
SubstrateConfig,
},
tx::{
PairSigner,
SubstrateExtrinsicParams,
},
tx::PairSigner,
OnlineClient,
};

Expand All @@ -34,10 +32,10 @@ impl Config for MyConfig {
type Index = u64;
type BlockNumber = <SubstrateConfig as Config>::BlockNumber;
type Hash = <SubstrateConfig as Config>::Hash;
type Hashing = <SubstrateConfig as Config>::Hashing;
type Hasher = <SubstrateConfig as Config>::Hasher;
type Header = <SubstrateConfig as Config>::Header;
type AccountId = <SubstrateConfig as Config>::AccountId;
type Address = <SubstrateConfig as Config>::Address;
type Header = <SubstrateConfig as Config>::Header;
type Signature = <SubstrateConfig as Config>::Signature;
// ExtrinsicParams makes use of the index type, so we need to adjust it
// too to align with our modified index type, above:
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/dynamic_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);

// Submit it:
let encoded = hex::encode(&api.tx().call_data(&tx)?);
let encoded = hex::encode(api.tx().call_data(&tx)?);
println!("Call data: {encoded}");
let tx_hash = api.tx().sign_and_submit_default(&tx, &signer).await?;
println!("Submitted tx with hash {tx_hash}");
Expand Down
12 changes: 5 additions & 7 deletions examples/examples/fetch_staking_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
//! polkadot --dev --tmp
//! ```

use sp_core::{
sr25519,
Pair,
};
use sp_keyring::AccountKeyring;
use subxt::{
ext::{
sp_core::{
sr25519,
Pair,
},
sp_runtime::AccountId32,
},
utils::AccountId32,
OnlineClient,
PolkadotConfig,
};
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// threshold
1,
// other signatories
vec![signer_account_id],
vec![signer_account_id.into()],
// maybe timepoint
None,
// call
Expand All @@ -67,7 +67,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);

// Submit the extrinsic with default params:
let encoded = hex::encode(&api.tx().call_data(&tx)?);
let encoded = hex::encode(api.tx().call_data(&tx)?);
println!("Call data: {encoded}");
let tx_hash = api.tx().sign_and_submit_default(&tx, &signer).await?;
println!("Submitted tx with hash {tx_hash}");
Expand Down
9 changes: 2 additions & 7 deletions examples/examples/rpc_call_subscribe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
//! ```

use subxt::{
ext::sp_runtime::{
generic::Header,
traits::BlakeTwo256,
},
rpc::Subscription,
config::Header,
OnlineClient,
PolkadotConfig,
};
Expand All @@ -28,8 +24,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?;

// For non-finalised blocks use `.subscribe_blocks()`
let mut blocks: Subscription<Header<u32, BlakeTwo256>> =
api.rpc().subscribe_finalized_block_headers().await?;
let mut blocks = api.rpc().subscribe_finalized_block_headers().await?;

while let Some(Ok(block)) = blocks.next().await {
println!(
Expand Down
2 changes: 1 addition & 1 deletion metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description = "Command line utilities for checking metadata compatibility betwee
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full"] }
frame-metadata = "15.0.0"
scale-info = "2.0.0"
sp-core = "7.0.0"
sp-core-hashing = "6.0.0"
ascjones marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
Expand Down
4 changes: 2 additions & 2 deletions metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ enum TypeBeingHashed {
}

/// Hashing function utilized internally.
fn hash(bytes: &[u8]) -> [u8; 32] {
sp_core::hashing::twox_256(bytes)
fn hash(data: &[u8]) -> [u8; 32] {
sp_core_hashing::twox_256(data)
}

/// XOR two hashes together. If we have two pseudorandom hashes, then this will
Expand Down
28 changes: 22 additions & 6 deletions subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ description = "Submit extrinsics (transactions) to a substrate node via RPC"
keywords = ["parity", "substrate", "blockchain"]

[features]
default = ["jsonrpsee-ws"]
default = ["jsonrpsee-ws", "substrate-compat"]

# Activate this feature to pull in extra Substrate dependencies which make it
# possible to provide a proper extrinsic Signer implementation (PairSigner).
substrate-compat = [
"sp-core",
"sp-runtime"
]

# Activate this to expose functionality only used for integration testing.
# The exposed functionality is subject to breaking changes at any point,
Expand All @@ -32,23 +39,32 @@ scale-info = "2.0.0"
scale-value = "0.6.0"
scale-bits = "0.3"
scale-decode = "0.4.0"
futures = { version = "0.3.13", default-features = false }
futures = { version = "0.3.13", default-features = false, features = ["std"] }
hex = "0.4.3"
jsonrpsee = { version = "0.16", optional = true, features = ["jsonrpsee-types"] }
serde = { version = "1.0.124", features = ["derive"] }
serde_json = { version = "1.0.64", features = ["raw_value"] }
thiserror = "1.0.24"
tracing = "0.1.34"
parking_lot = "0.12.0"
frame-metadata = "15.0.0"
derivative = "2.2.0"

subxt-macro = { version = "0.25.0", path = "../macro" }
subxt-metadata = { version = "0.25.0", path = "../metadata" }

sp-core = { version = "7.0.0", default-features = false }
sp-runtime = "7.0.0"
# Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256:
impl-serde = { version = "0.4.0" }
primitive-types = { version = "0.12.0", default-features = false, features = ["codec", "scale-info", "serde"] }
sp-core-hashing = "6.0.0"
ascjones marked this conversation as resolved.
Show resolved Hide resolved

frame-metadata = "15.0.0"
derivative = "2.2.0"
# For ss58 encoding AccountId32 to serialize them properly:
base58 = { version = "0.2.0" }
blake2 = { version = "0.10.4", default-features = false }

# These are only included is "substrate-compat" is enabled.
sp-core = { version = "10.0.0", default-features = false, optional = true }
sp-runtime = { version = "11.0.0", optional = true }

[target.wasm32-unknown-unknown.dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand Down
14 changes: 7 additions & 7 deletions subxt/src/blocks/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ use crate::{
OfflineClientT,
OnlineClientT,
},
config::{
Config,
Hasher,
Header,
},
error::{
BlockError,
Error,
},
events,
rpc::ChainBlockResponse,
Config,
};
use derivative::Derivative;
use futures::lock::Mutex as AsyncMutex;
use sp_runtime::traits::{
Hash,
Header,
};
use std::sync::Arc;

/// A representation of a block.
Expand Down Expand Up @@ -56,7 +56,7 @@ where

/// Return the block number.
pub fn number(&self) -> T::BlockNumber {
*self.header().number()
self.header().number()
}

/// Return the entire block header.
Expand Down Expand Up @@ -170,7 +170,7 @@ where
pub async fn events(&self) -> Result<ExtrinsicEvents<T>, Error> {
let events =
get_events(&self.client, self.block_hash, &self.cached_events).await?;
let ext_hash = T::Hashing::hash_of(&self.bytes);
let ext_hash = T::Hasher::hash_of(&self.bytes);
Ok(ExtrinsicEvents::new(ext_hash, self.index, events))
}
}
Expand Down
10 changes: 6 additions & 4 deletions subxt/src/blocks/blocks_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
use super::Block;
use crate::{
client::OnlineClientT,
config::{
Config,
Header,
},
error::{
BlockError,
Error,
},
utils::PhantomDataSendSync,
Config,
};
use derivative::Derivative;
use futures::{
Expand All @@ -19,7 +22,6 @@ use futures::{
Stream,
StreamExt,
};
use sp_runtime::traits::Header;
use std::{
future::Future,
pin::Pin,
Expand Down Expand Up @@ -137,7 +139,7 @@ where
.rpc()
.header(Some(last_finalized_block_hash))
.await?
.map(|h| (*h.number()).into());
.map(|h| h.number().into());

let sub = client.rpc().subscribe_finalized_block_headers().await?;

Expand Down Expand Up @@ -203,7 +205,7 @@ where
};

// We want all previous details up to, but not including this current block num.
let end_block_num = (*header.number()).into();
let end_block_num = header.number().into();

// This is one after the last block we returned details for last time.
let start_block_num = last_block_num.map(|n| n + 1).unwrap_or(end_block_num);
Expand Down
Loading