mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
b316301d61
* begin porting over traits; remove Config use of Hash * port over the Header bits that we need * sp_core_hashing where possible, move Verify to PairSigner, remove unused errors * tidy up Config things and move related bits into one place * fix codegen * copy Era over * move AccountId, Address, Signer to Signer trait and a pass over fixing examples * impl MultiAddress, MultiSignature, AccountId32 and add back to Config (for decoding later) * Copy over StorageKey, StorageData, StorageChangeSet * subxt core compiling with no sp_core or sp_runtime * Get examples compiling * pass over fixing tests * cargo fmt * clippy tweaks and update polkadot.rs * fix codegen docs * port over special DigestItem encoding/decoding * clippy and doc fixes * cargo fmt and example fix * more cargo fmt-ing... * substrate-extra to substrate-compat * cargo.toml comments * simplify PairSigner trait bounds * move RPC types to a separate file * fix docs * Add some tests for things and other PR feedback * bump to latest sp deps * avoid needing substrate-compat feature in a test
65 lines
2.3 KiB
Rust
65 lines
2.3 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.
|
|
|
|
//! This example should compile but should fail to work, since we've modified the
|
|
//! config to not align with a Polkadot node.
|
|
|
|
use sp_keyring::AccountKeyring;
|
|
use subxt::{
|
|
config::{
|
|
substrate::SubstrateExtrinsicParams,
|
|
Config,
|
|
SubstrateConfig,
|
|
},
|
|
tx::PairSigner,
|
|
OnlineClient,
|
|
};
|
|
|
|
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
|
|
pub mod polkadot {}
|
|
|
|
/// Custom [`Config`] impl where the default types for the target chain differ from the
|
|
/// [`DefaultConfig`]
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
|
pub struct MyConfig;
|
|
impl Config for MyConfig {
|
|
// This is different from the default `u32`.
|
|
//
|
|
// *Note* that in this example it does differ from the actual `Index` type in the
|
|
// polkadot runtime used, so some operations will fail. Normally when using a custom `Config`
|
|
// impl types MUST match exactly those used in the actual runtime.
|
|
type Index = u64;
|
|
type BlockNumber = <SubstrateConfig as Config>::BlockNumber;
|
|
type Hash = <SubstrateConfig as Config>::Hash;
|
|
type Hasher = <SubstrateConfig as Config>::Hasher;
|
|
type Header = <SubstrateConfig as Config>::Header;
|
|
type AccountId = <SubstrateConfig as Config>::AccountId;
|
|
type Address = <SubstrateConfig as Config>::Address;
|
|
type Signature = <SubstrateConfig as Config>::Signature;
|
|
// ExtrinsicParams makes use of the index type, so we need to adjust it
|
|
// too to align with our modified index type, above:
|
|
type ExtrinsicParams = SubstrateExtrinsicParams<Self>;
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let signer = PairSigner::new(AccountKeyring::Alice.pair());
|
|
let dest = AccountKeyring::Bob.to_account_id().into();
|
|
|
|
// Create a client to use:
|
|
let api = OnlineClient::<MyConfig>::new().await?;
|
|
|
|
// Create a transaction to submit:
|
|
let tx = polkadot::tx()
|
|
.balances()
|
|
.transfer(dest, 123_456_789_012_345);
|
|
|
|
// submit the transaction with default params:
|
|
let hash = api.tx().sign_and_submit_default(&tx, &signer).await?;
|
|
|
|
println!("Balance transfer extrinsic submitted: {}", hash);
|
|
|
|
Ok(())
|
|
}
|