-
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
Make storage futures only borrow client, not self, for better ergonomics #561
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f16bc9c
Allow storage requests to be made concurrently
jsdw 6c08190
fmt and license
jsdw b4e68cb
Update codegen/src/api/storage.rs
jsdw e5c24c4
Update codegen/src/api/storage.rs
jsdw d9f7cbe
split should_ref things up to move them closer to where they are used
jsdw 1e26fbf
Merge branch 'jsdw-storage-futs' of github.com:paritytech/subxt into …
jsdw e9221ab
fmt + clippy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 futures::join; | ||
use sp_keyring::AccountKeyring; | ||
use subxt::{ | ||
ClientBuilder, | ||
DefaultConfig, | ||
PolkadotExtrinsicParams, | ||
}; | ||
|
||
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")] | ||
pub mod polkadot {} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let api = ClientBuilder::new() | ||
.build() | ||
.await? | ||
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<DefaultConfig>>>(); | ||
|
||
let addr = AccountKeyring::Bob.to_account_id(); | ||
|
||
// For storage requests, we can join futures together to | ||
// await multiple futures concurrently: | ||
let a_fut = api.storage().staking().bonded(&addr, None); | ||
let b_fut = api.storage().staking().ledger(&addr, None); | ||
let (a, b) = join!(a_fut, b_fut); | ||
|
||
println!("{a:?}, {b:?}"); | ||
|
||
Ok(()) | ||
} |
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.
Note to self; key args have a lifetime of 'a, which is the same as the lifetime of the client struct.
Should key args have a lifetime of 'b, and the returned future rely on both 'a and 'b, to avoid any unnecessary restrictions on how the future is used in conjunction with these references?
It would be good to test and see whether a single bound is overly restrictive (as well as to test that we can create and later use futures so that we confirm it's all good in one place.
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 did a little testing and it seems OK to use the
'a
lifetime for key_args and client; from reading around I think Rust will pick the correct smallest lifetime that all params with'a
use anyway, so no need to add other lifetimes.