style: format subxt example files

This commit is contained in:
2026-01-04 21:24:40 +03:00
parent b1a94f6b99
commit 7670c52ad6
2 changed files with 299 additions and 281 deletions
+2 -4
View File
@@ -5,8 +5,8 @@
//! Run with: cargo run --example tx_pezkuwichain //! Run with: cargo run --example tx_pezkuwichain
#![allow(missing_docs)] #![allow(missing_docs)]
use pezkuwi_subxt::{OnlineClient, PezkuwiConfig};
use pezkuwi_subxt::config::pezkuwi::{AccountId32, MultiAddress}; use pezkuwi_subxt::config::pezkuwi::{AccountId32, MultiAddress};
use pezkuwi_subxt::{OnlineClient, PezkuwiConfig};
use pezkuwi_subxt_signer::sr25519::dev; use pezkuwi_subxt_signer::sr25519::dev;
// Generate interface from Pezkuwichain metadata // Generate interface from Pezkuwichain metadata
@@ -41,9 +41,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let bob_account = AccountId32(bob.public_key().0); let bob_account = AccountId32(bob.public_key().0);
let dest = MultiAddress::Id(bob_account); let dest = MultiAddress::Id(bob_account);
let transfer_tx = pezkuwichain::tx() let transfer_tx = pezkuwichain::tx().balances().transfer_allow_death(dest, transfer_amount);
.balances()
.transfer_allow_death(dest, transfer_amount);
// Sign and submit // Sign and submit
println!("\nSubmitting transaction..."); println!("\nSubmitting transaction...");
+76 -56
View File
@@ -14,9 +14,9 @@
//! Run with: cargo run --example xcm_reserve_transfer //! Run with: cargo run --example xcm_reserve_transfer
#![allow(missing_docs)] #![allow(missing_docs)]
use pezkuwi_subxt::{OnlineClient, PezkuwiConfig};
use pezkuwi_subxt::dynamic::{At, Value}; use pezkuwi_subxt::dynamic::{At, Value};
use pezkuwi_subxt::utils::AccountId32; use pezkuwi_subxt::utils::AccountId32;
use pezkuwi_subxt::{OnlineClient, PezkuwiConfig};
use pezkuwi_subxt_signer::sr25519::dev; use pezkuwi_subxt_signer::sr25519::dev;
use std::time::Duration; use std::time::Duration;
@@ -43,13 +43,10 @@ async fn query_relay_balance(
let storage = api.storage().at_latest().await?; let storage = api.storage().at_latest().await?;
// Use dynamic storage query for flexibility // Use dynamic storage query for flexibility
let storage_query = pezkuwi_subxt::dynamic::storage::<(AccountId32,), Value>("System", "Account"); let storage_query =
pezkuwi_subxt::dynamic::storage::<(AccountId32,), Value>("System", "Account");
let account_info = storage let account_info = storage.entry(storage_query)?.fetch((account.clone(),)).await?.decode()?;
.entry(storage_query)?
.fetch((account.clone(),))
.await?
.decode()?;
// Extract the free balance using the At trait // Extract the free balance using the At trait
let free_balance = account_info let free_balance = account_info
@@ -70,13 +67,10 @@ async fn query_asset_hub_balance(
let storage = api.storage().at_latest().await?; let storage = api.storage().at_latest().await?;
// Use dynamic storage query for flexibility // Use dynamic storage query for flexibility
let storage_query = pezkuwi_subxt::dynamic::storage::<(AccountId32,), Value>("System", "Account"); let storage_query =
pezkuwi_subxt::dynamic::storage::<(AccountId32,), Value>("System", "Account");
let account_info = storage let account_info = storage.entry(storage_query)?.fetch((account.clone(),)).await?.decode()?;
.entry(storage_query)?
.fetch((account.clone(),))
.await?
.decode()?;
// Extract the free balance using the At trait // Extract the free balance using the At trait
let free_balance = account_info let free_balance = account_info
@@ -127,22 +121,27 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let relay_balance_before = query_relay_balance(&relay_api, &alice_account_id).await?; let relay_balance_before = query_relay_balance(&relay_api, &alice_account_id).await?;
println!(" Alice on Relay Chain:"); println!(" Alice on Relay Chain:");
println!(" Free balance: {} TYR ({:.4} HEZ)", println!(
" Free balance: {} TYR ({:.4} HEZ)",
relay_balance_before, relay_balance_before,
relay_balance_before as f64 / PLANCKS_PER_HEZ as f64); relay_balance_before as f64 / PLANCKS_PER_HEZ as f64
);
let asset_hub_balance_before = match query_asset_hub_balance(&asset_hub_api, &alice_account_id).await { let asset_hub_balance_before =
match query_asset_hub_balance(&asset_hub_api, &alice_account_id).await {
Ok(balance) => balance, Ok(balance) => balance,
Err(_) => { Err(_) => {
println!(" Alice on Asset Hub: (Account not found - will be created)"); println!(" Alice on Asset Hub: (Account not found - will be created)");
0 0
} },
}; };
if asset_hub_balance_before > 0 { if asset_hub_balance_before > 0 {
println!(" Alice on Asset Hub:"); println!(" Alice on Asset Hub:");
println!(" Free balance: {} TYR ({:.4} HEZ)", println!(
" Free balance: {} TYR ({:.4} HEZ)",
asset_hub_balance_before, asset_hub_balance_before,
asset_hub_balance_before as f64 / PLANCKS_PER_HEZ as f64); asset_hub_balance_before as f64 / PLANCKS_PER_HEZ as f64
);
} }
// ═══════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════
@@ -159,38 +158,43 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dest = relay::runtime_types::xcm::VersionedLocation::V4( let dest = relay::runtime_types::xcm::VersionedLocation::V4(
relay::runtime_types::pezstaging_xcm::v4::location::Location { relay::runtime_types::pezstaging_xcm::v4::location::Location {
parents: 0, parents: 0,
interior: relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::X1( interior: relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::X1([
[relay::runtime_types::pezstaging_xcm::v4::junction::Junction::Teyrchain(ASSET_HUB_PARA_ID)] relay::runtime_types::pezstaging_xcm::v4::junction::Junction::Teyrchain(
ASSET_HUB_PARA_ID,
), ),
} ]),
},
); );
// Build beneficiary: Alice's account on Asset Hub // Build beneficiary: Alice's account on Asset Hub
let beneficiary = relay::runtime_types::xcm::VersionedLocation::V4( let beneficiary = relay::runtime_types::xcm::VersionedLocation::V4(
relay::runtime_types::pezstaging_xcm::v4::location::Location { relay::runtime_types::pezstaging_xcm::v4::location::Location {
parents: 0, parents: 0,
interior: relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::X1( interior: relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::X1([
[relay::runtime_types::pezstaging_xcm::v4::junction::Junction::AccountId32 { relay::runtime_types::pezstaging_xcm::v4::junction::Junction::AccountId32 {
network: None, network: None,
id: alice.public_key().0, id: alice.public_key().0,
}] },
), ]),
} },
); );
// Build assets: Native token (HEZ) // Build assets: Native token (HEZ)
let assets = relay::runtime_types::xcm::VersionedAssets::V4( let assets = relay::runtime_types::xcm::VersionedAssets::V4(
relay::runtime_types::pezstaging_xcm::v4::asset::Assets( relay::runtime_types::pezstaging_xcm::v4::asset::Assets(vec![
vec![relay::runtime_types::pezstaging_xcm::v4::asset::Asset { relay::runtime_types::pezstaging_xcm::v4::asset::Asset {
id: relay::runtime_types::pezstaging_xcm::v4::asset::AssetId( id: relay::runtime_types::pezstaging_xcm::v4::asset::AssetId(
relay::runtime_types::pezstaging_xcm::v4::location::Location { relay::runtime_types::pezstaging_xcm::v4::location::Location {
parents: 0, parents: 0,
interior: relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::Here, interior:
} relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::Here,
},
), ),
fun: relay::runtime_types::pezstaging_xcm::v4::asset::Fungibility::Fungible(transfer_amount), fun: relay::runtime_types::pezstaging_xcm::v4::asset::Fungibility::Fungible(
}] transfer_amount,
) ),
},
]),
); );
// Weight limit: Unlimited // Weight limit: Unlimited
@@ -202,8 +206,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
relay::runtime_types::pezstaging_xcm::v4::location::Location { relay::runtime_types::pezstaging_xcm::v4::location::Location {
parents: 0, parents: 0,
interior: relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::Here, interior: relay::runtime_types::pezstaging_xcm::v4::junctions::Junctions::Here,
} },
) ),
); );
// Build the extrinsic - Use teleport for system teyrchains (Asset Hub) // Build the extrinsic - Use teleport for system teyrchains (Asset Hub)
@@ -218,10 +222,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("\n Submitting XCM transaction to Relay Chain..."); println!("\n Submitting XCM transaction to Relay Chain...");
let tx_progress = relay_api let tx_progress = relay_api.tx().sign_and_submit_then_watch_default(&xcm_tx, &alice).await?;
.tx()
.sign_and_submit_then_watch_default(&xcm_tx, &alice)
.await?;
println!(" Transaction submitted, waiting for finalization..."); println!(" Transaction submitted, waiting for finalization...");
@@ -239,7 +240,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Some(event) => { Some(event) => {
println!("✓ XCM Attempted event:"); println!("✓ XCM Attempted event:");
println!(" Outcome: {:?}", event.outcome); println!(" Outcome: {:?}", event.outcome);
} },
None => println!("⚠ No Attempted event found"), None => println!("⚠ No Attempted event found"),
} }
@@ -249,7 +250,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("✓ XCM Sent event:"); println!("✓ XCM Sent event:");
println!(" Origin: {:?}", event.origin); println!(" Origin: {:?}", event.origin);
println!(" Destination: {:?}", event.destination); println!(" Destination: {:?}", event.destination);
} },
None => println!("⚠ No Sent event found"), None => println!("⚠ No Sent event found"),
} }
@@ -258,7 +259,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Some(event) => { Some(event) => {
println!("✓ XCM FeesPaid event:"); println!("✓ XCM FeesPaid event:");
println!(" Fees: {:?}", event.fees); println!(" Fees: {:?}", event.fees);
} },
None => println!(" (No FeesPaid event - fees may be zero)"), None => println!(" (No FeesPaid event - fees may be zero)"),
} }
@@ -276,7 +277,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("\n═══ STEP 7: Query final balances ═══"); println!("\n═══ STEP 7: Query final balances ═══");
let relay_balance_after = query_relay_balance(&relay_api, &alice_account_id).await?; let relay_balance_after = query_relay_balance(&relay_api, &alice_account_id).await?;
let asset_hub_balance_after = query_asset_hub_balance(&asset_hub_api, &alice_account_id).await.unwrap_or(0); let asset_hub_balance_after =
query_asset_hub_balance(&asset_hub_api, &alice_account_id).await.unwrap_or(0);
// ═══════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════
// STEP 8: Results and verification // STEP 8: Results and verification
@@ -289,20 +291,38 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let asset_hub_diff = asset_hub_balance_after.saturating_sub(asset_hub_balance_before); let asset_hub_diff = asset_hub_balance_after.saturating_sub(asset_hub_balance_before);
println!("║ RELAY CHAIN (Alice): ║"); println!("║ RELAY CHAIN (Alice): ║");
println!("║ Before: {:>20} TYR ({:>10.4} HEZ) ║", println!(
relay_balance_before, relay_balance_before as f64 / PLANCKS_PER_HEZ as f64); "║ Before: {:>20} TYR ({:>10.4} HEZ) ║",
println!("║ After: {:>20} TYR ({:>10.4} HEZ) ║", relay_balance_before,
relay_balance_after, relay_balance_after as f64 / PLANCKS_PER_HEZ as f64); relay_balance_before as f64 / PLANCKS_PER_HEZ as f64
println!("║ Spent: {:>20} TYR ({:>10.4} HEZ) ║", );
relay_diff, relay_diff as f64 / PLANCKS_PER_HEZ as f64); println!(
"║ After: {:>20} TYR ({:>10.4} HEZ) ║",
relay_balance_after,
relay_balance_after as f64 / PLANCKS_PER_HEZ as f64
);
println!(
"║ Spent: {:>20} TYR ({:>10.4} HEZ) ║",
relay_diff,
relay_diff as f64 / PLANCKS_PER_HEZ as f64
);
println!("║ ║"); println!("║ ║");
println!("║ ASSET HUB (Alice): ║"); println!("║ ASSET HUB (Alice): ║");
println!("║ Before: {:>20} TYR ({:>10.4} HEZ) ║", println!(
asset_hub_balance_before, asset_hub_balance_before as f64 / PLANCKS_PER_HEZ as f64); "║ Before: {:>20} TYR ({:>10.4} HEZ) ║",
println!("║ After: {:>20} TYR ({:>10.4} HEZ) ║", asset_hub_balance_before,
asset_hub_balance_after, asset_hub_balance_after as f64 / PLANCKS_PER_HEZ as f64); asset_hub_balance_before as f64 / PLANCKS_PER_HEZ as f64
println!("║ Received: {:>18} TYR ({:>10.4} HEZ) ║", );
asset_hub_diff, asset_hub_diff as f64 / PLANCKS_PER_HEZ as f64); println!(
"║ After: {:>20} TYR ({:>10.4} HEZ) ║",
asset_hub_balance_after,
asset_hub_balance_after as f64 / PLANCKS_PER_HEZ as f64
);
println!(
"║ Received: {:>18} TYR ({:>10.4} HEZ) ║",
asset_hub_diff,
asset_hub_diff as f64 / PLANCKS_PER_HEZ as f64
);
println!("╠══════════════════════════════════════════════════════════════╣"); println!("╠══════════════════════════════════════════════════════════════╣");
// Verification // Verification