substrate_api_client/api/runtime_api/
transaction_payment_call.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, FeeDetails, RuntimeDispatchInfo, Weight};
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 TransactionPaymentCallApi: RuntimeApi {
24	type FeeDetails;
25	type RuntimeDispatchInfo;
26	type Balance;
27	type Weight;
28
29	/// Query the call fee details.
30	async fn query_call_fee_details<Call: Encode>(
31		&self,
32		call: Call,
33		length: u32,
34		at_block: Option<Self::Hash>,
35	) -> Result<Self::FeeDetails>;
36
37	/// Query the call info
38	async fn query_call_info<Call: Encode>(
39		&self,
40		call: Call,
41		length: u32,
42		at_block: Option<Self::Hash>,
43	) -> Result<Self::RuntimeDispatchInfo>;
44
45	/// Query the output of the current LengthToFee given some input.
46	async fn query_length_to_fee_call(
47		&self,
48		length: u32,
49		at_block: Option<Self::Hash>,
50	) -> Result<Self::Balance>;
51
52	/// Query the output of the current WeightToFee given some input.
53	async fn query_weight_to_fee_call(
54		&self,
55		weight: Self::Weight,
56		at_block: Option<Self::Hash>,
57	) -> Result<Self::Balance>;
58}
59
60#[maybe_async::maybe_async(?Send)]
61impl<T, Client> TransactionPaymentCallApi for RuntimeApiClient<T, Client>
62where
63	T: Config,
64	Client: Request,
65{
66	type FeeDetails = FeeDetails<T::Balance>;
67	type RuntimeDispatchInfo = RuntimeDispatchInfo<T::Balance>;
68	type Balance = T::Balance;
69	type Weight = Weight;
70
71	async fn query_call_fee_details<Call: Encode>(
72		&self,
73		call: Call,
74		length: u32,
75		at_block: Option<Self::Hash>,
76	) -> Result<Self::FeeDetails> {
77		self.runtime_call(
78			"TransactionPaymentCallApi_query_call_fee_details",
79			vec![call.encode(), length.encode()],
80			at_block,
81		)
82		.await
83	}
84
85	async fn query_call_info<Call: Encode>(
86		&self,
87		call: Call,
88		length: u32,
89		at_block: Option<Self::Hash>,
90	) -> Result<Self::RuntimeDispatchInfo> {
91		self.runtime_call(
92			"TransactionPaymentCallApi_query_call_info",
93			vec![call.encode(), length.encode()],
94			at_block,
95		)
96		.await
97	}
98
99	async fn query_length_to_fee_call(
100		&self,
101		length: u32,
102		at_block: Option<Self::Hash>,
103	) -> Result<Self::Balance> {
104		self.runtime_call(
105			"TransactionPaymentCallApi_query_length_to_fee",
106			vec![length.encode()],
107			at_block,
108		)
109		.await
110	}
111
112	async fn query_weight_to_fee_call(
113		&self,
114		weight: Self::Weight,
115		at_block: Option<Self::Hash>,
116	) -> Result<Self::Balance> {
117		self.runtime_call(
118			"TransactionPaymentCallApi_query_weight_to_fee",
119			vec![weight.encode()],
120			at_block,
121		)
122		.await
123	}
124}