-
Notifications
You must be signed in to change notification settings - Fork 254
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
Simplify creating and signing extrinsics #490
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e6f8818
WIP extrinsic api updates
jsdw 7c6c690
First pass done; now to get things compiling again
jsdw 7cc2b5f
document and tweak new structs/traits
jsdw 0c13fb9
cargo check --all-targets now compiles without issue
jsdw 5a72227
Polkadot and Substrate take different extra params; support both
jsdw 75db75f
Fix transaction format (missing byte from AccountId -> Address) and fmt
jsdw 8c88c41
Tweak Signer trait
jsdw 49ef09e
Tweak comments and such in extrinsic params
jsdw 47ab585
check all examples against newer polkadot, add new one with params, i…
jsdw 59d8fdd
clippy fix, and save an allocation when signing
jsdw 6012d2a
Remove unnecessary Default clauses
jsdw 403d57b
Tidy up and fix comments. Panic if payload size >4GB
jsdw 251d07d
fix typo
jsdw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,69 @@ | ||
// 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/>. | ||
|
||
//! To run this example, a local polkadot node should be running. Example verified against polkadot 0.9.18-f6d6ab005d-aarch64-macos. | ||
//! | ||
//! E.g. | ||
//! ```bash | ||
//! curl "https://github.com/paritytech/polkadot/releases/download/v0.9.13/polkadot" --output /usr/local/bin/polkadot --location | ||
//! polkadot --dev --tmp | ||
//! ``` | ||
|
||
use sp_keyring::AccountKeyring; | ||
use subxt::{ | ||
extrinsic::{ | ||
Era, | ||
PlainTip, | ||
}, | ||
ClientBuilder, | ||
DefaultConfig, | ||
PairSigner, | ||
PolkadotExtrinsicParams, | ||
PolkadotExtrinsicParamsBuilder as Params, | ||
}; | ||
|
||
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")] | ||
pub mod polkadot {} | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
env_logger::init(); | ||
|
||
let signer = PairSigner::new(AccountKeyring::Alice.pair()); | ||
let dest = AccountKeyring::Bob.to_account_id().into(); | ||
|
||
let api = ClientBuilder::new() | ||
.build() | ||
.await? | ||
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<DefaultConfig>>>(); | ||
|
||
// Configure the transaction tip and era: | ||
let tx_params = Params::new() | ||
.tip(PlainTip::new(20_000_000_000)) | ||
.era(Era::Immortal, *api.client.genesis()); | ||
|
||
// Send the transaction: | ||
let hash = api | ||
.tx() | ||
.balances() | ||
.transfer(dest, 123_456_789_012_345) | ||
.sign_and_submit(&signer, tx_params) | ||
.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
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
Binary file not shown.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure whether this is possible/desirable, but did you consider adding a builder style method onto
SubmittableExtrinsic
which allows setting the params, and would use the default if not specified e.g.It would avoid the requirement of the
_default
method equivalents, on the other hand would be less explicit if adding params is the common case.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.
Ooh interesting! I didn't consider that offhand, no.
One thing I like about having the
_default
and the param-taking methods is that it's up to the user whether the params actually do implementDefault
at all or not; theDefault
constraint is only on those_default
methods now, so if for some reason somebody could not or did not want a default set of params for their chain, that'd work just fine.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 say that but actually I think I left a Default clause somewhere I shouldn't have, so this is a good pointer to remove that!done!