Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Get account nonce via state_call; remove RPC method #1002

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions subxt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>;
type Index: Debug + Copy + Decode + Into<u64>;

/// The output of the `Hasher` function.
type Hash: Debug
Expand All @@ -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<Self::AccountId>;
Expand Down
11 changes: 0 additions & 11 deletions subxt/src/rpc/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use std::sync::Arc;

use codec::{Decode, Encode};
use serde::Serialize;

use crate::{error::Error, utils::PhantomDataSendSync, Config, Metadata};

Expand Down Expand Up @@ -179,16 +178,6 @@ impl<T: Config> Rpc<T> {
self.client.request("system_version", rpc_params![]).await
}

/// Fetch the current nonce for the given account ID.
pub async fn system_account_next_index<AccountId: Serialize>(
&self,
account: &AccountId,
) -> Result<T::Index, Error> {
self.client
.request("system_accountNextIndex", rpc_params![account])
.await
}

/// Get a header
pub async fn header(&self, hash: Option<T::Hash>) -> Result<Option<T::Header>, Error> {
let params = rpc_params![hash];
Expand Down
14 changes: 9 additions & 5 deletions subxt/src/tx/tx_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,15 @@ where
T: Config,
C: OnlineClientT<T>,
{
// Get the next account nonce to use.
async fn next_account_nonce(&self, account_id: &T::AccountId) -> Result<T::Index, Error> {
/// Get the account nonce for a given account ID.
pub async fn account_nonce(&self, account_id: &T::AccountId) -> Result<T::Index, Error> {
self.client
.rpc()
.system_account_next_index(account_id)
.state_call(
"AccountNonceApi_account_nonce",
Some(&account_id.encode()),
None,
)
.await
}

Expand All @@ -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)
}

Expand All @@ -207,7 +211,7 @@ where
Call: TxPayload,
Signer: SignerT<T>,
{
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)
}

Expand Down