substrate_api_client/api/runtime_api/
account_nonce.rs

1/*
2   Copyright 2024 Supercomputing Systems AG
3   Licensed under the Apache License, Version 2.0 (the "License");
4   you may not use this file except in compliance with the License.
5   You may obtain a copy of the License at
6	   http://www.apache.org/licenses/LICENSE-2.0
7   Unless required by applicable law or agreed to in writing, software
8   distributed under the License is distributed on an "AS IS" BASIS,
9   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10   See the License for the specific language governing permissions and
11   limitations under the License.
12*/
13
14use super::{RuntimeApi, RuntimeApiClient};
15use crate::{api::Result, rpc::Request};
16use ac_primitives::config::Config;
17#[cfg(not(feature = "sync-api"))]
18use alloc::boxed::Box;
19use alloc::vec;
20use sp_core::Encode;
21
22#[maybe_async::maybe_async(?Send)]
23pub trait AccountNonceApi: RuntimeApi {
24	type Index;
25	type AccountId;
26
27	/// The API to query account nonce (aka transaction index).
28	async fn account_nonce(
29		&self,
30		account_id: Self::AccountId,
31		at_block: Option<Self::Hash>,
32	) -> Result<Self::Index>;
33}
34
35#[maybe_async::maybe_async(?Send)]
36impl<T, Client> AccountNonceApi for RuntimeApiClient<T, Client>
37where
38	T: Config,
39	Client: Request,
40{
41	type Index = T::Index;
42	type AccountId = T::AccountId;
43
44	async fn account_nonce(
45		&self,
46		account_id: Self::AccountId,
47		at_block: Option<Self::Hash>,
48	) -> Result<Self::Index> {
49		self.runtime_call("AccountNonceApi_account_nonce", vec![account_id.encode()], at_block)
50			.await
51	}
52}