-
Notifications
You must be signed in to change notification settings - Fork 262
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
Parameterize AccountData
#409
Changes from 5 commits
f3130cc
079efaa
7f3a167
be43687
afb0beb
c466529
9f810f0
b040cbb
5eb9695
e13a989
a07714c
275e948
6cd1637
5a8916c
797be56
2c3f388
0a138e1
28fbe60
c1a1610
9d6a658
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 {} | ||
|
||
#[derive(Clone, Debug, Default, Eq, PartialEq)] | ||
pub struct MyConfig; | ||
impl Config for MyConfig { | ||
type Index = <DefaultConfig as Config>::Index; | ||
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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for the sake of the example, could we actually override one or more of these types perhaps (maybe then with a comment saying what's going on), just to make it clear that that's sortof the point of this impl? (I realise that doing so may prevent it from actually working below; something that would want to be made clear also.) |
||
|
||
#[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 _ = api | ||
.tx() | ||
.balances() | ||
.transfer(dest, 10_000) | ||
.sign_and_submit(&signer) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this example would be more useful if we made a more plausible change to the config, something a project might actually want to do. Not for this PR, it'd be more like a tutorial I reckon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be best accompanied with an actual runtime with the different type