mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 14:47:55 +00:00
Make storage futures only borrow client, not self, for better ergonomics (#561)
* Allow storage requests to be made concurrently * fmt and license * Update codegen/src/api/storage.rs Capitalise comment Co-authored-by: Tarik Gul <47201679+TarikGul@users.noreply.github.com> * Update codegen/src/api/storage.rs Capitalise comment Co-authored-by: Tarik Gul <47201679+TarikGul@users.noreply.github.com> * split should_ref things up to move them closer to where they are used * fmt + clippy Co-authored-by: Tarik Gul <47201679+TarikGul@users.noreply.github.com>
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
Reference in New Issue
Block a user