Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multisig static example #713

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added artifacts/substrate_metadata.scale
Binary file not shown.
66 changes: 66 additions & 0 deletions examples/examples/multisig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 substrate latest-38a955ba4a0.
//!
//! E.g.
//! ```bash
//! curl "https://releases.parity.io/substrate/x86_64-debian:stretch/latest/substrate/substrate" --output /usr/local/bin/substrate --location
//! substrate --dev --tmp
//! ```
Comment on lines +5 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only example using Substrate? I think just for consistency with other examples maybe it's best to stick to Polkadot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Polkadot node does not contain the Assets pallet, at least I didn't see it in the metadata of wss://rpc.polkadot.io:443

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's ok; we don't need to specifically use this Assets call as the example; in https://github.com/paritytech/subxt/pull/714/files I used a balance transfer so perhaps we could standardise and both just do that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think I'll rename my example to dynamic_multisig.rs to align with yours :)


use sp_keyring::AccountKeyring;
use subxt::{
tx::PairSigner,
OnlineClient,
SubstrateConfig,
};

#[subxt::subxt(runtime_metadata_path = "../artifacts/substrate_metadata.scale")]
pub mod substrate {}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();

let signer = PairSigner::new(AccountKeyring::Alice.pair());

// Create a client to use:
let api = OnlineClient::<SubstrateConfig>::new().await?;

// The call data of for the `Multisig::as_multi`.
// This must be of type `RuntimeCall` and represents the `Assets::freeze_asset` method.
// Otherwise, could have been obtained using
// `substrate::tx().assets().freeze_asset(100)`
let call = substrate::runtime_types::kitchensink_runtime::RuntimeCall::Assets(
substrate::runtime_types::pallet_assets::pallet::Call::freeze_asset { id: 100 },
);
Comment on lines +35 to +37
Copy link
Collaborator

@jsdw jsdw Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about:

substrate::tx().assets().freeze_asset(100).call_data().clone()

does that work instead?

And if so, perhaps we could add an into_call_data() to mirror the into_value() I added on the dynamic side, and avoid the clone here?

It'd be awesome if we can add that and make embedding calls like this way smoother!


// The maximum weight (gas) for this extrinsic.
let max_weight = substrate::runtime_types::sp_weights::weight_v2::Weight {
ref_time: 10000000000,
proof_size: u64::MAX / 2,
};

// Construct the multisig extrinsic.
let tx = substrate::tx().multisig().as_multi(
// threashold
1,
// other signatories
vec![AccountKeyring::Alice.to_account_id()],
// maybe timepoint
None,
// call
call,
// max weight
max_weight,
);

// Submit the transaction with default params:
let hash = api.tx().sign_and_submit_default(&tx, &signer).await?;

println!("Multisig extrinsic submitted: {:?}", hash);

Ok(())
}