diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index b776689c3c..d94f04810d 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -27,7 +27,7 @@ pub use substrate::SubstrateConfig; pub trait Config: 'static { /// Account index (aka nonce) type. This stores the number of previous /// transactions associated with a sender account. - type Index: Debug + Copy + DeserializeOwned + Into; + type Index: Debug + Copy + Decode + Into; /// The output of the `Hasher` function. type Hash: Debug @@ -42,7 +42,7 @@ pub trait Config: 'static { + PartialEq; /// The account ID type. - type AccountId: Debug + Clone + Serialize; + type AccountId: Debug + Clone + Encode; /// The address type. type Address: Debug + Encode + From; diff --git a/subxt/src/rpc/rpc.rs b/subxt/src/rpc/rpc.rs index 64e1fc6cc8..37dafb5f06 100644 --- a/subxt/src/rpc/rpc.rs +++ b/subxt/src/rpc/rpc.rs @@ -34,7 +34,6 @@ use std::sync::Arc; use codec::{Decode, Encode}; -use serde::Serialize; use crate::{error::Error, utils::PhantomDataSendSync, Config, Metadata}; @@ -179,16 +178,6 @@ impl Rpc { self.client.request("system_version", rpc_params![]).await } - /// Fetch the current nonce for the given account ID. - pub async fn system_account_next_index( - &self, - account: &AccountId, - ) -> Result { - self.client - .request("system_accountNextIndex", rpc_params![account]) - .await - } - /// Get a header pub async fn header(&self, hash: Option) -> Result, Error> { let params = rpc_params![hash]; diff --git a/subxt/src/tx/tx_client.rs b/subxt/src/tx/tx_client.rs index 87ac93ad08..5f3ce2943d 100644 --- a/subxt/src/tx/tx_client.rs +++ b/subxt/src/tx/tx_client.rs @@ -174,11 +174,15 @@ where T: Config, C: OnlineClientT, { - // Get the next account nonce to use. - async fn next_account_nonce(&self, account_id: &T::AccountId) -> Result { + /// Get the account nonce for a given account ID. + pub async fn account_nonce(&self, account_id: &T::AccountId) -> Result { self.client .rpc() - .system_account_next_index(account_id) + .state_call( + "AccountNonceApi_account_nonce", + Some(&account_id.encode()), + None, + ) .await } @@ -192,7 +196,7 @@ where where Call: TxPayload, { - let account_nonce = self.next_account_nonce(account_id).await?; + let account_nonce = self.account_nonce(account_id).await?; self.create_partial_signed_with_nonce(call, account_nonce, other_params) } @@ -207,7 +211,7 @@ where Call: TxPayload, Signer: SignerT, { - let account_nonce = self.next_account_nonce(signer.account_id()).await?; + let account_nonce = self.account_nonce(signer.account_id()).await?; self.create_signed_with_nonce(call, signer, account_nonce, other_params) }