substrate_api_client/api/runtime_api/
staking.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(all(not(feature = "sync-api"), not(feature = "std")))]
18use alloc::boxed::Box;
19use alloc::vec;
20use sp_core::Encode;
21
22#[maybe_async::maybe_async(?Send)]
23pub trait StakingApi: RuntimeApi {
24	type Balance;
25
26	/// Returns the nominations quota for a nominator with a given balance.
27	async fn nominations_quota(
28		&self,
29		balance: Self::Balance,
30		at_block: Option<Self::Hash>,
31	) -> Result<u32>;
32}
33
34#[maybe_async::maybe_async(?Send)]
35impl<T, Client> StakingApi for RuntimeApiClient<T, Client>
36where
37	T: Config,
38	Client: Request,
39{
40	type Balance = T::Balance;
41
42	async fn nominations_quota(
43		&self,
44		balance: Self::Balance,
45		at_block: Option<Self::Hash>,
46	) -> Result<u32> {
47		self.runtime_call("StakingApi_nominations_quota", vec![balance.encode()], at_block)
48			.await
49	}
50}