From 0e0553a022bc49ed2533b383f055f211bd895cec Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 16 Feb 2022 10:18:18 +0000 Subject: [PATCH] Expose method to fetch nonce via `Client` (#451) --- subxt/src/client.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/subxt/src/client.rs b/subxt/src/client.rs index 7eb8935c6f..f4929641a5 100644 --- a/subxt/src/client.rs +++ b/subxt/src/client.rs @@ -167,6 +167,23 @@ impl Client { StorageClient::new(&self.rpc, &self.metadata, self.iter_page_size) } + /// Fetch the current nonce for the given account id. + pub async fn fetch_nonce( + &self, + account: &T::AccountId, + ) -> Result + where + ::AccountId: From<::AccountId>, + ::Index: Into<::Index>, + { + let account_storage_entry = A::storage_entry(account.clone().into()); + let account_data = self + .storage() + .fetch_or_default(&account_storage_entry, None) + .await?; + Ok(A::nonce(&account_data).into()) + } + /// Convert the client to a runtime api wrapper for custom runtime access. /// /// The `subxt` proc macro will provide methods to submit extrinsics and read storage specific @@ -264,14 +281,7 @@ where let account_nonce = if let Some(nonce) = signer.nonce() { nonce } else { - let account_storage_entry = - A::storage_entry(signer.account_id().clone().into()); - let account_data = self - .client - .storage() - .fetch_or_default(&account_storage_entry, None) - .await?; - A::nonce(&account_data).into() + self.client.fetch_nonce::(signer.account_id()).await? }; let call = self .client