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

* begin porting over traits; remove Config use of Hash

* port over the Header bits that we need

* sp_core_hashing where possible, move Verify to PairSigner, remove unused errors

* tidy up Config things and move related bits into one place

* fix codegen

* copy Era over

* move AccountId, Address, Signer to Signer trait and a pass over fixing examples

* impl MultiAddress, MultiSignature, AccountId32 and add back to Config (for decoding later)

* Copy over StorageKey, StorageData, StorageChangeSet

* subxt core compiling with no sp_core or sp_runtime

* Get examples compiling

* pass over fixing tests

* cargo fmt

* clippy tweaks and update polkadot.rs

* fix codegen docs

* port over special DigestItem encoding/decoding

* clippy and doc fixes

* cargo fmt and example fix

* more cargo fmt-ing...

* substrate-extra to substrate-compat

* cargo.toml comments

* simplify PairSigner trait bounds

* move RPC types to a separate file

* fix docs

* Add some tests for things and other PR feedback

* bump to latest sp deps

* avoid needing substrate-compat feature in a test
This commit is contained in:
James Wilson
2023-01-10 12:02:41 +00:00
committed by GitHub
parent ea5daa444f
commit b316301d61
47 changed files with 2658 additions and 1736 deletions
@@ -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")]
@@ -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);
+4 -6
View File
@@ -8,13 +8,11 @@
use sp_keyring::AccountKeyring;
use subxt::{
config::{
substrate::SubstrateExtrinsicParams,
Config,
SubstrateConfig,
},
tx::{
PairSigner,
SubstrateExtrinsicParams,
},
tx::PairSigner,
OnlineClient,
};
@@ -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:
+5 -7
View File
@@ -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,
};
+1 -1
View File
@@ -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
@@ -11,11 +11,7 @@
//! ```
use subxt::{
ext::sp_runtime::{
generic::Header,
traits::BlakeTwo256,
},
rpc::Subscription,
config::Header,
OnlineClient,
PolkadotConfig,
};
@@ -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!(