use super::{RuntimeApi, RuntimeApiClient};
use crate::{api::Result, rpc::Request};
use ac_primitives::{config::Config, FeeDetails, RuntimeDispatchInfo, Weight};
#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
use alloc::boxed::Box;
use alloc::vec;
use sp_core::Encode;
#[maybe_async::maybe_async(?Send)]
pub trait TransactionPaymentCallApi: RuntimeApi {
type FeeDetails;
type RuntimeDispatchInfo;
type Balance;
type Weight;
async fn query_call_fee_details<Call: Encode>(
&self,
call: Call,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::FeeDetails>;
async fn query_call_info<Call: Encode>(
&self,
call: Call,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::RuntimeDispatchInfo>;
async fn query_length_to_fee_call(
&self,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance>;
async fn query_weight_to_fee_call(
&self,
weight: Self::Weight,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance>;
}
#[maybe_async::maybe_async(?Send)]
impl<T, Client> TransactionPaymentCallApi for RuntimeApiClient<T, Client>
where
T: Config,
Client: Request,
{
type FeeDetails = FeeDetails<T::Balance>;
type RuntimeDispatchInfo = RuntimeDispatchInfo<T::Balance>;
type Balance = T::Balance;
type Weight = Weight;
async fn query_call_fee_details<Call: Encode>(
&self,
call: Call,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::FeeDetails> {
self.runtime_call(
"TransactionPaymentCallApi_query_call_fee_details",
vec![call.encode(), length.encode()],
at_block,
)
.await
}
async fn query_call_info<Call: Encode>(
&self,
call: Call,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::RuntimeDispatchInfo> {
self.runtime_call(
"TransactionPaymentCallApi_query_call_info",
vec![call.encode(), length.encode()],
at_block,
)
.await
}
async fn query_length_to_fee_call(
&self,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance> {
self.runtime_call(
"TransactionPaymentCallApi_query_length_to_fee",
vec![length.encode()],
at_block,
)
.await
}
async fn query_weight_to_fee_call(
&self,
weight: Self::Weight,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance> {
self.runtime_call(
"TransactionPaymentCallApi_query_weight_to_fee",
vec![weight.encode()],
at_block,
)
.await
}
}