style: format subxt example files
This commit is contained in:
+40
-42
@@ -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
|
||||||
@@ -15,56 +15,54 @@ pub mod pezkuwichain {}
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("=== PEZKUWICHAIN TOKEN TRANSFER TEST ===\n");
|
println!("=== PEZKUWICHAIN TOKEN TRANSFER TEST ===\n");
|
||||||
|
|
||||||
// Connect to local node (default port 9944)
|
// Connect to local node (default port 9944)
|
||||||
let api = OnlineClient::<PezkuwiConfig>::from_url("ws://127.0.0.1:9944").await?;
|
let api = OnlineClient::<PezkuwiConfig>::from_url("ws://127.0.0.1:9944").await?;
|
||||||
println!("✓ Connected to Pezkuwichain node");
|
println!("✓ Connected to Pezkuwichain node");
|
||||||
|
|
||||||
// Setup accounts
|
// Setup accounts
|
||||||
let alice = dev::alice();
|
let alice = dev::alice();
|
||||||
let bob = dev::bob();
|
let bob = dev::bob();
|
||||||
|
|
||||||
println!("\n--- Accounts ---");
|
println!("\n--- Accounts ---");
|
||||||
println!("Alice: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY");
|
println!("Alice: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY");
|
||||||
println!("Bob: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty");
|
println!("Bob: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty");
|
||||||
|
|
||||||
// Transfer amount: 1 HEZ = 1_000_000_000_000 TYR (10^12)
|
// Transfer amount: 1 HEZ = 1_000_000_000_000 TYR (10^12)
|
||||||
let transfer_amount: u128 = 1_000_000_000_000; // 1 HEZ
|
let transfer_amount: u128 = 1_000_000_000_000; // 1 HEZ
|
||||||
|
|
||||||
println!("\n--- Executing Transfer ---");
|
println!("\n--- Executing Transfer ---");
|
||||||
println!("From: Alice");
|
println!("From: Alice");
|
||||||
println!("To: Bob");
|
println!("To: Bob");
|
||||||
println!("Amount: {} TYR (1 HEZ)", transfer_amount);
|
println!("Amount: {} TYR (1 HEZ)", transfer_amount);
|
||||||
|
|
||||||
// Build transfer extrinsic using utility types
|
// Build transfer extrinsic using utility types
|
||||||
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...");
|
||||||
let events = api
|
let events = api
|
||||||
.tx()
|
.tx()
|
||||||
.sign_and_submit_then_watch_default(&transfer_tx, &alice)
|
.sign_and_submit_then_watch_default(&transfer_tx, &alice)
|
||||||
.await?
|
.await?
|
||||||
.wait_for_finalized_success()
|
.wait_for_finalized_success()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
println!("✓ Transaction finalized!");
|
println!("✓ Transaction finalized!");
|
||||||
|
|
||||||
// Find Transfer event
|
// Find Transfer event
|
||||||
let transfer_event = events.find_first::<pezkuwichain::balances::events::Transfer>()?;
|
let transfer_event = events.find_first::<pezkuwichain::balances::events::Transfer>()?;
|
||||||
if let Some(event) = transfer_event {
|
if let Some(event) = transfer_event {
|
||||||
println!("\n✓ Transfer event:");
|
println!("\n✓ Transfer event:");
|
||||||
println!(" From: {:?}", event.from);
|
println!(" From: {:?}", event.from);
|
||||||
println!(" To: {:?}", event.to);
|
println!(" To: {:?}", event.to);
|
||||||
println!(" Amount: {} TYR", event.amount);
|
println!(" Amount: {} TYR", event.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("\n=== TEST COMPLETED SUCCESSFULLY ===");
|
println!("\n=== TEST COMPLETED SUCCESSFULLY ===");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
+259
-239
@@ -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;
|
||||||
|
|
||||||
@@ -37,295 +37,315 @@ const PLANCKS_PER_HEZ: u128 = 1_000_000_000_000;
|
|||||||
|
|
||||||
/// Query balance from relay chain using dynamic storage query
|
/// Query balance from relay chain using dynamic storage query
|
||||||
async fn query_relay_balance(
|
async fn query_relay_balance(
|
||||||
api: &OnlineClient<PezkuwiConfig>,
|
api: &OnlineClient<PezkuwiConfig>,
|
||||||
account: &AccountId32,
|
account: &AccountId32,
|
||||||
) -> Result<u128, Box<dyn std::error::Error>> {
|
) -> Result<u128, Box<dyn std::error::Error>> {
|
||||||
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
|
||||||
.at("data")
|
.at("data")
|
||||||
.at("free")
|
.at("free")
|
||||||
.ok_or("Could not find free balance")?
|
.ok_or("Could not find free balance")?
|
||||||
.as_u128()
|
.as_u128()
|
||||||
.ok_or("Could not parse free balance as u128")?;
|
.ok_or("Could not parse free balance as u128")?;
|
||||||
|
|
||||||
Ok(free_balance)
|
Ok(free_balance)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Query balance from Asset Hub using dynamic storage query
|
/// Query balance from Asset Hub using dynamic storage query
|
||||||
async fn query_asset_hub_balance(
|
async fn query_asset_hub_balance(
|
||||||
api: &OnlineClient<PezkuwiConfig>,
|
api: &OnlineClient<PezkuwiConfig>,
|
||||||
account: &AccountId32,
|
account: &AccountId32,
|
||||||
) -> Result<u128, Box<dyn std::error::Error>> {
|
) -> Result<u128, Box<dyn std::error::Error>> {
|
||||||
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
|
||||||
.at("data")
|
.at("data")
|
||||||
.at("free")
|
.at("free")
|
||||||
.ok_or("Could not find free balance")?
|
.ok_or("Could not find free balance")?
|
||||||
.as_u128()
|
.as_u128()
|
||||||
.ok_or("Could not parse free balance as u128")?;
|
.ok_or("Could not parse free balance as u128")?;
|
||||||
|
|
||||||
Ok(free_balance)
|
Ok(free_balance)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("╔══════════════════════════════════════════════════════════════╗");
|
println!("╔══════════════════════════════════════════════════════════════╗");
|
||||||
println!("║ XCM RESERVE TRANSFER TEST - PEZKUWICHAIN ║");
|
println!("║ XCM RESERVE TRANSFER TEST - PEZKUWICHAIN ║");
|
||||||
println!("╠══════════════════════════════════════════════════════════════╣");
|
println!("╠══════════════════════════════════════════════════════════════╣");
|
||||||
println!("║ From: Relay Chain (HEZ) ║");
|
println!("║ From: Relay Chain (HEZ) ║");
|
||||||
println!("║ To: Asset Hub Teyrchain (Para {}) ║", ASSET_HUB_PARA_ID);
|
println!("║ To: Asset Hub Teyrchain (Para {}) ║", ASSET_HUB_PARA_ID);
|
||||||
println!("╚══════════════════════════════════════════════════════════════╝\n");
|
println!("╚══════════════════════════════════════════════════════════════╝\n");
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
// STEP 1: Connect to both chains
|
// STEP 1: Connect to both chains
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
println!("═══ STEP 1: Connecting to chains ═══");
|
println!("═══ STEP 1: Connecting to chains ═══");
|
||||||
|
|
||||||
let relay_api = OnlineClient::<PezkuwiConfig>::from_url(RELAY_RPC).await?;
|
let relay_api = OnlineClient::<PezkuwiConfig>::from_url(RELAY_RPC).await?;
|
||||||
println!("✓ Connected to Relay Chain at {}", RELAY_RPC);
|
println!("✓ Connected to Relay Chain at {}", RELAY_RPC);
|
||||||
|
|
||||||
let asset_hub_api = OnlineClient::<PezkuwiConfig>::from_url(ASSET_HUB_RPC).await?;
|
let asset_hub_api = OnlineClient::<PezkuwiConfig>::from_url(ASSET_HUB_RPC).await?;
|
||||||
println!("✓ Connected to Asset Hub at {}", ASSET_HUB_RPC);
|
println!("✓ Connected to Asset Hub at {}", ASSET_HUB_RPC);
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
// STEP 2: Setup accounts
|
// STEP 2: Setup accounts
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
println!("\n═══ STEP 2: Setup accounts ═══");
|
println!("\n═══ STEP 2: Setup accounts ═══");
|
||||||
|
|
||||||
let alice = dev::alice();
|
let alice = dev::alice();
|
||||||
let alice_account_id = AccountId32(alice.public_key().0);
|
let alice_account_id = AccountId32(alice.public_key().0);
|
||||||
|
|
||||||
println!("✓ Using Alice account");
|
println!("✓ Using Alice account");
|
||||||
println!(" Address: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY");
|
println!(" Address: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY");
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
// STEP 3: Query initial balances
|
// STEP 3: Query initial balances
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
println!("\n═══ STEP 3: Query initial balances ═══");
|
println!("\n═══ STEP 3: Query initial balances ═══");
|
||||||
|
|
||||||
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!(
|
||||||
relay_balance_before,
|
" Free balance: {} TYR ({:.4} HEZ)",
|
||||||
relay_balance_before as f64 / PLANCKS_PER_HEZ as f64);
|
relay_balance_before,
|
||||||
|
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 =
|
||||||
Ok(balance) => balance,
|
match query_asset_hub_balance(&asset_hub_api, &alice_account_id).await {
|
||||||
Err(_) => {
|
Ok(balance) => balance,
|
||||||
println!(" Alice on Asset Hub: (Account not found - will be created)");
|
Err(_) => {
|
||||||
0
|
println!(" Alice on Asset Hub: (Account not found - will be created)");
|
||||||
}
|
0
|
||||||
};
|
},
|
||||||
if asset_hub_balance_before > 0 {
|
};
|
||||||
println!(" Alice on Asset Hub:");
|
if asset_hub_balance_before > 0 {
|
||||||
println!(" Free balance: {} TYR ({:.4} HEZ)",
|
println!(" Alice on Asset Hub:");
|
||||||
asset_hub_balance_before,
|
println!(
|
||||||
asset_hub_balance_before as f64 / PLANCKS_PER_HEZ as f64);
|
" Free balance: {} TYR ({:.4} HEZ)",
|
||||||
}
|
asset_hub_balance_before,
|
||||||
|
asset_hub_balance_before as f64 / PLANCKS_PER_HEZ as f64
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
// STEP 4: Build and submit XCM teleport (for system teyrchains)
|
// STEP 4: Build and submit XCM teleport (for system teyrchains)
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
println!("\n═══ STEP 4: Execute XCM Teleport ═══");
|
println!("\n═══ STEP 4: Execute XCM Teleport ═══");
|
||||||
|
|
||||||
// Transfer 0.1 HEZ (100 billion planck)
|
// Transfer 0.1 HEZ (100 billion planck)
|
||||||
// Note: Alice has ~1 HEZ after previous transactions, so keep transfer small
|
// Note: Alice has ~1 HEZ after previous transactions, so keep transfer small
|
||||||
let transfer_amount: u128 = PLANCKS_PER_HEZ / 10; // 0.1 HEZ
|
let transfer_amount: u128 = PLANCKS_PER_HEZ / 10; // 0.1 HEZ
|
||||||
println!(" Transfer amount: {} TYR (0.1 HEZ)", transfer_amount);
|
println!(" Transfer amount: {} TYR (0.1 HEZ)", transfer_amount);
|
||||||
|
|
||||||
// Build destination: Asset Hub (Teyrchain 1000) - Note: Junction::Teyrchain not Parachain
|
// Build destination: Asset Hub (Teyrchain 1000) - Note: Junction::Teyrchain not Parachain
|
||||||
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
|
||||||
let weight_limit = relay::runtime_types::xcm::v3::WeightLimit::Unlimited;
|
let weight_limit = relay::runtime_types::xcm::v3::WeightLimit::Unlimited;
|
||||||
|
|
||||||
// Fee asset item - use the native asset (index 0 in assets array, converted to VersionedAssetId)
|
// Fee asset item - use the native asset (index 0 in assets array, converted to VersionedAssetId)
|
||||||
let fee_asset = relay::runtime_types::xcm::VersionedAssetId::V4(
|
let fee_asset = relay::runtime_types::xcm::VersionedAssetId::V4(
|
||||||
relay::runtime_types::pezstaging_xcm::v4::asset::AssetId(
|
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,
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Build the extrinsic - Use teleport for system teyrchains (Asset Hub)
|
// Build the extrinsic - Use teleport for system teyrchains (Asset Hub)
|
||||||
// Note: System teyrchains like Asset Hub support teleportation from relay chain
|
// Note: System teyrchains like Asset Hub support teleportation from relay chain
|
||||||
let xcm_tx = relay::tx().xcm_pallet().limited_teleport_assets(
|
let xcm_tx = relay::tx().xcm_pallet().limited_teleport_assets(
|
||||||
dest,
|
dest,
|
||||||
beneficiary,
|
beneficiary,
|
||||||
assets,
|
assets,
|
||||||
fee_asset,
|
fee_asset,
|
||||||
weight_limit,
|
weight_limit,
|
||||||
);
|
);
|
||||||
|
|
||||||
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...");
|
||||||
|
|
||||||
let events = tx_progress.wait_for_finalized_success().await?;
|
let events = tx_progress.wait_for_finalized_success().await?;
|
||||||
|
|
||||||
println!("✓ Transaction finalized on Relay Chain!");
|
println!("✓ Transaction finalized on Relay Chain!");
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
// STEP 5: Check XCM events
|
// STEP 5: Check XCM events
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
println!("\n═══ STEP 5: Analyze XCM events ═══");
|
println!("\n═══ STEP 5: Analyze XCM events ═══");
|
||||||
|
|
||||||
// Check for Attempted event
|
// Check for Attempted event
|
||||||
match events.find_first::<relay::xcm_pallet::events::Attempted>()? {
|
match events.find_first::<relay::xcm_pallet::events::Attempted>()? {
|
||||||
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"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for Sent event
|
// Check for Sent event
|
||||||
match events.find_first::<relay::xcm_pallet::events::Sent>()? {
|
match events.find_first::<relay::xcm_pallet::events::Sent>()? {
|
||||||
Some(event) => {
|
Some(event) => {
|
||||||
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"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for FeesPaid event
|
// Check for FeesPaid event
|
||||||
match events.find_first::<relay::xcm_pallet::events::FeesPaid>()? {
|
match events.find_first::<relay::xcm_pallet::events::FeesPaid>()? {
|
||||||
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)"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
// STEP 6: Wait for XCM to be processed on Asset Hub
|
// STEP 6: Wait for XCM to be processed on Asset Hub
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
println!("\n═══ STEP 6: Wait for Asset Hub processing ═══");
|
println!("\n═══ STEP 6: Wait for Asset Hub processing ═══");
|
||||||
println!(" Waiting 12 seconds for XCM message to be delivered and processed...");
|
println!(" Waiting 12 seconds for XCM message to be delivered and processed...");
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_secs(12)).await;
|
tokio::time::sleep(Duration::from_secs(12)).await;
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
// STEP 7: Query final balances
|
// STEP 7: Query final balances
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
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
|
||||||
// ═══════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════
|
||||||
println!("\n╔══════════════════════════════════════════════════════════════╗");
|
println!("\n╔══════════════════════════════════════════════════════════════╗");
|
||||||
println!("║ TEST RESULTS ║");
|
println!("║ TEST RESULTS ║");
|
||||||
println!("╠══════════════════════════════════════════════════════════════╣");
|
println!("╠══════════════════════════════════════════════════════════════╣");
|
||||||
|
|
||||||
let relay_diff = relay_balance_before.saturating_sub(relay_balance_after);
|
let relay_diff = relay_balance_before.saturating_sub(relay_balance_after);
|
||||||
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!(
|
||||||
println!("║ ║");
|
"║ After: {:>20} TYR ({:>10.4} HEZ) ║",
|
||||||
println!("║ ASSET HUB (Alice): ║");
|
relay_balance_after,
|
||||||
println!("║ Before: {:>20} TYR ({:>10.4} HEZ) ║",
|
relay_balance_after as f64 / PLANCKS_PER_HEZ as f64
|
||||||
asset_hub_balance_before, asset_hub_balance_before as f64 / PLANCKS_PER_HEZ as f64);
|
);
|
||||||
println!("║ After: {:>20} TYR ({:>10.4} HEZ) ║",
|
println!(
|
||||||
asset_hub_balance_after, asset_hub_balance_after as f64 / PLANCKS_PER_HEZ as f64);
|
"║ Spent: {:>20} TYR ({:>10.4} HEZ) ║",
|
||||||
println!("║ Received: {:>18} TYR ({:>10.4} HEZ) ║",
|
relay_diff,
|
||||||
asset_hub_diff, asset_hub_diff as f64 / PLANCKS_PER_HEZ as f64);
|
relay_diff as f64 / PLANCKS_PER_HEZ as f64
|
||||||
println!("╠══════════════════════════════════════════════════════════════╣");
|
);
|
||||||
|
println!("║ ║");
|
||||||
|
println!("║ ASSET HUB (Alice): ║");
|
||||||
|
println!(
|
||||||
|
"║ Before: {:>20} TYR ({:>10.4} HEZ) ║",
|
||||||
|
asset_hub_balance_before,
|
||||||
|
asset_hub_balance_before 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!("╠══════════════════════════════════════════════════════════════╣");
|
||||||
|
|
||||||
// Verification
|
// Verification
|
||||||
if asset_hub_diff > 0 {
|
if asset_hub_diff > 0 {
|
||||||
let fees = transfer_amount.saturating_sub(asset_hub_diff);
|
let fees = transfer_amount.saturating_sub(asset_hub_diff);
|
||||||
println!("║ ✓ SUCCESS: XCM transfer completed! ║");
|
println!("║ ✓ SUCCESS: XCM transfer completed! ║");
|
||||||
println!("║ Transferred: {} TYR ║", transfer_amount);
|
println!("║ Transferred: {} TYR ║", transfer_amount);
|
||||||
println!("║ Received: {} TYR ║", asset_hub_diff);
|
println!("║ Received: {} TYR ║", asset_hub_diff);
|
||||||
println!("║ XCM Fees: {} TYR ║", fees);
|
println!("║ XCM Fees: {} TYR ║", fees);
|
||||||
println!("╚══════════════════════════════════════════════════════════════╝");
|
println!("╚══════════════════════════════════════════════════════════════╝");
|
||||||
println!("\n✓ XCM RESERVE TRANSFER TEST PASSED!");
|
println!("\n✓ XCM RESERVE TRANSFER TEST PASSED!");
|
||||||
} else if relay_diff > 0 {
|
} else if relay_diff > 0 {
|
||||||
println!("║ ⚠ PARTIAL: Tokens deducted from Relay but not yet on AH ║");
|
println!("║ ⚠ PARTIAL: Tokens deducted from Relay but not yet on AH ║");
|
||||||
println!("║ This may indicate XCM is still processing ║");
|
println!("║ This may indicate XCM is still processing ║");
|
||||||
println!("║ or there was an error on the receiving side ║");
|
println!("║ or there was an error on the receiving side ║");
|
||||||
println!("╚══════════════════════════════════════════════════════════════╝");
|
println!("╚══════════════════════════════════════════════════════════════╝");
|
||||||
println!("\n⚠ XCM TEST NEEDS INVESTIGATION");
|
println!("\n⚠ XCM TEST NEEDS INVESTIGATION");
|
||||||
} else {
|
} else {
|
||||||
println!("║ ✗ FAILED: No balance change detected ║");
|
println!("║ ✗ FAILED: No balance change detected ║");
|
||||||
println!("║ Check logs for XCM processing errors ║");
|
println!("║ Check logs for XCM processing errors ║");
|
||||||
println!("╚══════════════════════════════════════════════════════════════╝");
|
println!("╚══════════════════════════════════════════════════════════════╝");
|
||||||
println!("\n✗ XCM RESERVE TRANSFER TEST FAILED");
|
println!("\n✗ XCM RESERVE TRANSFER TEST FAILED");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user