forked from paritytech/subxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parameterize
AccountData
(paritytech#409)
* Add custom config example * Make account data storage item configurable * Fix contracts * Regenerate polkadot codegen * Fmt * Specify different type for `MyConfig::Index` * Update comment in custom config example * Assign concrete types for default AccountData impl * Fmt * Fix contracts tests * Fmt * Add comments * Unlink doc comment trait (subxt not in scope) * Fix missing nonce field error message * Update codegen/src/api/mod.rs Co-authored-by: David <[email protected]> * Update examples/custom_config.rs Co-authored-by: David <[email protected]> * Rename Nonce assoc type to Index for consistency * Add module level docs about codegen assumptions Co-authored-by: David <[email protected]>
- Loading branch information
1 parent
65b75d3
commit ab83d8a
Showing
6 changed files
with
664 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2019-2022 Parity Technologies (UK) Ltd. | ||
// This file is part of subxt. | ||
// | ||
// subxt is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// subxt is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with subxt. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use sp_keyring::AccountKeyring; | ||
use subxt::{ | ||
ClientBuilder, | ||
Config, | ||
DefaultConfig, | ||
DefaultExtra, | ||
PairSigner, | ||
}; | ||
|
||
#[subxt::subxt(runtime_metadata_path = "examples/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 = <DefaultConfig as Config>::BlockNumber; | ||
type Hash = <DefaultConfig as Config>::Hash; | ||
type Hashing = <DefaultConfig as Config>::Hashing; | ||
type AccountId = <DefaultConfig as Config>::AccountId; | ||
type Address = <DefaultConfig as Config>::Address; | ||
type Header = <DefaultConfig as Config>::Header; | ||
type Signature = <DefaultConfig as Config>::Signature; | ||
type Extrinsic = <DefaultConfig as Config>::Extrinsic; | ||
} | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let api = ClientBuilder::new() | ||
.build() | ||
.await? | ||
.to_runtime_api::<polkadot::RuntimeApi<MyConfig, DefaultExtra<MyConfig>>>(); | ||
|
||
let signer = PairSigner::new(AccountKeyring::Alice.pair()); | ||
let dest = AccountKeyring::Bob.to_account_id().into(); | ||
|
||
let hash = api | ||
.tx() | ||
.balances() | ||
.transfer(dest, 10_000) | ||
.sign_and_submit(&signer) | ||
.await?; | ||
|
||
println!("Balance transfer extrinsic submitted: {}", hash); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.