cargo fmt with stable defaults (#876)

This commit is contained in:
James Wilson
2023-03-21 16:53:47 +00:00
committed by GitHub
parent c63ff6ec6d
commit 7c252fccf7
110 changed files with 663 additions and 1949 deletions
+1 -5
View File
@@ -11,11 +11,7 @@
//! ```
use sp_keyring::AccountKeyring;
use subxt::{
tx::PairSigner,
OnlineClient,
PolkadotConfig,
};
use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
@@ -13,11 +13,7 @@
use sp_keyring::AccountKeyring;
use subxt::{
config::{
polkadot::{
Era,
PlainTip,
PolkadotExtrinsicParamsBuilder as Params,
},
polkadot::{Era, PlainTip, PolkadotExtrinsicParamsBuilder as Params},
PolkadotConfig,
},
tx::PairSigner,
@@ -12,10 +12,7 @@
use futures::join;
use sp_keyring::AccountKeyring;
use subxt::{
OnlineClient,
PolkadotConfig,
};
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
+1 -5
View File
@@ -7,11 +7,7 @@
use sp_keyring::AccountKeyring;
use subxt::{
config::{
substrate::SubstrateExtrinsicParams,
Config,
SubstrateConfig,
},
config::{substrate::SubstrateExtrinsicParams, Config, SubstrateConfig},
tx::PairSigner,
OnlineClient,
};
+3 -12
View File
@@ -5,20 +5,11 @@
use std::{
fmt::Write,
pin::Pin,
sync::{
Arc,
Mutex,
},
sync::{Arc, Mutex},
};
use subxt::{
rpc::{
RawValue,
RpcClientT,
RpcFuture,
RpcSubscription,
},
OnlineClient,
PolkadotConfig,
rpc::{RawValue, RpcClientT, RpcFuture, RpcSubscription},
OnlineClient, PolkadotConfig,
};
// A dummy RPC client that doesn't actually handle requests properly
+1 -6
View File
@@ -11,12 +11,7 @@
//! ```
use sp_keyring::AccountKeyring;
use subxt::{
dynamic::Value,
tx::PairSigner,
OnlineClient,
PolkadotConfig,
};
use subxt::{dynamic::Value, tx::PairSigner, OnlineClient, PolkadotConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
+1 -6
View File
@@ -13,12 +13,7 @@
// This example showcases working with dynamic values rather than those that are generated via the subxt proc macro.
use sp_keyring::AccountKeyring;
use subxt::{
dynamic::Value,
tx::PairSigner,
OnlineClient,
PolkadotConfig,
};
use subxt::{dynamic::Value, tx::PairSigner, OnlineClient, PolkadotConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
+1 -4
View File
@@ -10,10 +10,7 @@
//! polkadot --dev --tmp
//! ```
use subxt::{
OnlineClient,
PolkadotConfig,
};
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
+1 -4
View File
@@ -10,10 +10,7 @@
//! polkadot --dev --tmp
//! ```
use subxt::{
OnlineClient,
PolkadotConfig,
};
use subxt::{OnlineClient, PolkadotConfig};
// Generate the API from a static metadata path.
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
+2 -9
View File
@@ -10,16 +10,9 @@
//! polkadot --dev --tmp
//! ```
use sp_core::{
sr25519,
Pair,
};
use sp_core::{sr25519, Pair};
use sp_keyring::AccountKeyring;
use subxt::{
utils::AccountId32,
OnlineClient,
PolkadotConfig,
};
use subxt::{utils::AccountId32, OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
+1 -4
View File
@@ -10,10 +10,7 @@
//! polkadot --dev --tmp
//! ```
use subxt::{
OnlineClient,
PolkadotConfig,
};
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
+1 -5
View File
@@ -11,11 +11,7 @@
//! ```
use sp_keyring::AccountKeyring;
use subxt::{
tx::PairSigner,
OnlineClient,
PolkadotConfig,
};
use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
+1 -4
View File
@@ -10,10 +10,7 @@
//! polkadot --dev --tmp
//! ```
use subxt::{
OnlineClient,
PolkadotConfig,
};
use subxt::{OnlineClient, PolkadotConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -10,18 +10,13 @@
//! polkadot --dev --tmp
//! ```
use subxt::{
config::Header,
OnlineClient,
PolkadotConfig,
};
use subxt::{config::Header, OnlineClient, PolkadotConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let api =
OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?;
let api = OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?;
// For non-finalised blocks use `.subscribe_blocks()`
let mut blocks = api.rpc().subscribe_finalized_block_headers().await?;
+1 -5
View File
@@ -11,11 +11,7 @@
use sp_core::H256;
use sp_runtime::{
generic,
traits::{
BlakeTwo256,
Block as _,
Header as _,
},
traits::{BlakeTwo256, Block as _, Header as _},
Digest,
};
use subxt::PolkadotConfig;
+4 -14
View File
@@ -10,14 +10,8 @@
//! polkadot --dev --tmp
//! ```
use codec::{
Decode,
Encode,
};
use subxt::{
OnlineClient,
PolkadotConfig,
};
use codec::{Decode, Encode};
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
@@ -60,9 +54,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
for key in keys.iter() {
println!("Key: 0x{}", hex::encode(key));
if let Some(storage_data) =
api.storage().at(None).await?.fetch_raw(&key.0).await?
{
if let Some(storage_data) = api.storage().at(None).await?.fetch_raw(&key.0).await? {
// We know the return value to be `QueryId` (`u64`) from inspecting either:
// - polkadot code
// - polkadot.rs generated file under `version_notifiers()` fn
@@ -102,9 +94,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
for key in keys.iter() {
println!("Key: 0x{}", hex::encode(key));
if let Some(storage_data) =
api.storage().at(None).await?.fetch_raw(&key.0).await?
{
if let Some(storage_data) = api.storage().at(None).await?.fetch_raw(&key.0).await? {
// We know the return value to be `QueryId` (`u64`) from inspecting either:
// - polkadot code
// - polkadot.rs generated file under `version_notifiers()` fn
+7 -18
View File
@@ -12,11 +12,7 @@
use futures::StreamExt;
use sp_keyring::AccountKeyring;
use subxt::{
tx::PairSigner,
OnlineClient,
PolkadotConfig,
};
use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
@@ -50,8 +46,7 @@ async fn simple_transfer() -> Result<(), Box<dyn std::error::Error>> {
.wait_for_finalized_success()
.await?;
let transfer_event =
balance_transfer.find_first::<polkadot::balances::events::Transfer>()?;
let transfer_event = balance_transfer.find_first::<polkadot::balances::events::Transfer>()?;
if let Some(event) = transfer_event {
println!("Balance transfer success: {event:?}");
@@ -88,8 +83,7 @@ async fn simple_transfer_separate_events() -> Result<(), Box<dyn std::error::Err
// the above, but does not check for success, and leaves it up to you:
let events = balance_transfer.fetch_events().await?;
let failed_event =
events.find_first::<polkadot::system::events::ExtrinsicFailed>()?;
let failed_event = events.find_first::<polkadot::system::events::ExtrinsicFailed>()?;
if let Some(_ev) = failed_event {
// We found a failed event; the transfer didn't succeed.
@@ -97,8 +91,7 @@ async fn simple_transfer_separate_events() -> Result<(), Box<dyn std::error::Err
} else {
// We didn't find a failed event; the transfer succeeded. Find
// more details about it to report..
let transfer_event =
events.find_first::<polkadot::balances::events::Transfer>()?;
let transfer_event = events.find_first::<polkadot::balances::events::Transfer>()?;
if let Some(event) = transfer_event {
println!("Balance transfer success: {event:?}");
} else {
@@ -138,13 +131,10 @@ async fn handle_transfer_events() -> Result<(), Box<dyn std::error::Error>> {
);
let events = details.wait_for_success().await?;
let transfer_event =
events.find_first::<polkadot::balances::events::Transfer>()?;
let transfer_event = events.find_first::<polkadot::balances::events::Transfer>()?;
if let Some(event) = transfer_event {
println!(
"Balance transfer is now in block (but not finalized): {event:?}"
);
println!("Balance transfer is now in block (but not finalized): {event:?}");
} else {
println!("Failed to find Balances::Transfer Event");
}
@@ -158,8 +148,7 @@ async fn handle_transfer_events() -> Result<(), Box<dyn std::error::Error>> {
);
let events = details.wait_for_success().await?;
let transfer_event =
events.find_first::<polkadot::balances::events::Transfer>()?;
let transfer_event = events.find_first::<polkadot::balances::events::Transfer>()?;
if let Some(event) = transfer_event {
println!("Balance transfer success: {event:?}");
+6 -14
View File
@@ -13,11 +13,7 @@
use futures::StreamExt;
use sp_keyring::AccountKeyring;
use std::time::Duration;
use subxt::{
tx::PairSigner,
OnlineClient,
PolkadotConfig,
};
use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
@@ -43,10 +39,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Make small balance transfers from Alice to Bob in a loop:
loop {
let transfer_tx = polkadot::tx().balances().transfer(
AccountKeyring::Bob.to_account_id().into(),
transfer_amount,
);
let transfer_tx = polkadot::tx()
.balances()
.transfer(AccountKeyring::Bob.to_account_id().into(), transfer_amount);
api.tx()
.sign_and_submit_default(&transfer_tx, &signer)
.await
@@ -76,14 +71,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.is_some();
let pallet = event.pallet_name();
let variant = event.variant_name();
println!(
" {pallet}::{variant} (is balance transfer? {is_balance_transfer})"
);
println!(" {pallet}::{variant} (is balance transfer? {is_balance_transfer})");
}
// Or we can find the first transfer event, ignoring any others:
let transfer_event =
events.find_first::<polkadot::balances::events::Transfer>()?;
let transfer_event = events.find_first::<polkadot::balances::events::Transfer>()?;
if let Some(ev) = transfer_event {
println!(" - Balance transfer success: value: {:?}", ev.amount);
+1 -4
View File
@@ -11,10 +11,7 @@
//! ```
use futures::StreamExt;
use subxt::{
OnlineClient,
PolkadotConfig,
};
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
@@ -11,10 +11,7 @@
//! ```
use std::time::Duration;
use subxt::{
OnlineClient,
PolkadotConfig,
};
use subxt::{OnlineClient, PolkadotConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {