mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 08:27:55 +00:00
92ace0629a
* First pass adding functions to get blocks and extrinsics * cargo fmt and cache block events * prefix block hash with 0x * pin streams for better ergonomics and add an example of subscribing to blocks * remove unused var * standardise on _all, _best and _finalized for different block header subs * WIP center subscribing around blocks * Remove the event filtering/subscribing stuff * clippy * we need tokio, silly clippy * add extrinsic_index() call * Update subxt/src/blocks/block_types.rs Co-authored-by: Andrew Jones <ascjones@gmail.com> * Add dynbamic nested query example and make dynamic::tx a little easier to work with * calL_value -> inner_tx * rename example to dynamic_multisig to align with #713 naming * align dynamic and static multisig examples * Fix comment typo Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> Co-authored-by: Andrew Jones <ascjones@gmail.com> Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
80 lines
2.4 KiB
Rust
80 lines
2.4 KiB
Rust
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
|
|
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
|
// see LICENSE for license details.
|
|
|
|
//! To run this example, a local polkadot node should be running. Example verified against polkadot v0.9.31-3711c6f9b2a.
|
|
//!
|
|
//! E.g.
|
|
//! ```bash
|
|
//! curl "https://github.com/paritytech/polkadot/releases/download/v0.9.31/polkadot" --output /usr/local/bin/polkadot --location
|
|
//! polkadot --dev --tmp
|
|
//! ```
|
|
|
|
use sp_keyring::AccountKeyring;
|
|
use subxt::{
|
|
dynamic::Value,
|
|
tx::PairSigner,
|
|
OnlineClient,
|
|
PolkadotConfig,
|
|
};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
// My account.
|
|
let signer_account = AccountKeyring::Alice;
|
|
let signer_account_id = signer_account.to_account_id();
|
|
let signer = PairSigner::new(signer_account.pair());
|
|
|
|
// Transfer balance to this destination:
|
|
let dest = AccountKeyring::Bob.to_account_id();
|
|
|
|
// Create a client to use:
|
|
let api = OnlineClient::<PolkadotConfig>::new().await?;
|
|
|
|
// Create the inner balance transfer call.
|
|
let inner_tx = subxt::dynamic::tx(
|
|
"Balances",
|
|
"transfer",
|
|
vec![
|
|
Value::unnamed_variant("Id", [Value::from_bytes(&dest)]),
|
|
Value::u128(123_456_789_012_345),
|
|
],
|
|
);
|
|
|
|
// Now, build an outer call which this inner call will be a part of.
|
|
// This sets up the multisig arrangement.
|
|
//
|
|
// Note: Since this is a dynamic call, we can either use named or unnamed
|
|
// arguments (if unnamed, the order matters).
|
|
let tx = subxt::dynamic::tx(
|
|
"Multisig",
|
|
"as_multi",
|
|
vec![
|
|
("threshold", Value::u128(1)),
|
|
(
|
|
"other_signatories",
|
|
Value::unnamed_composite([Value::from_bytes(&signer_account_id)]),
|
|
),
|
|
("maybe_timepoint", Value::unnamed_variant("None", [])),
|
|
("call", inner_tx.into_value()),
|
|
(
|
|
"max_weight",
|
|
Value::named_composite([
|
|
("ref_time", Value::u128(10000000000)),
|
|
("proof_size", Value::u128(1)),
|
|
]),
|
|
),
|
|
],
|
|
);
|
|
|
|
// Submit it:
|
|
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}");
|
|
|
|
Ok(())
|
|
}
|