use super::{RuntimeApi, RuntimeApiClient};
use crate::{api::Result, rpc::Request};
use ac_primitives::{config::Config, FeeDetails, RuntimeDispatchInfo, UncheckedExtrinsic, Weight};
#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
use alloc::boxed::Box;
use alloc::{vec, vec::Vec};
use sp_core::Encode;
#[maybe_async::maybe_async(?Send)]
pub trait TransactionPaymentApi: RuntimeApi {
type FeeDetails;
type RuntimeDispatchInfo;
type Balance;
type Weight;
async fn query_fee_details<Address, Call, Signature, TransactionExtension>(
&self,
extrinsic: UncheckedExtrinsic<Address, Call, Signature, TransactionExtension>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::FeeDetails>
where
Address: Encode,
Call: Encode,
Signature: Encode,
TransactionExtension: Encode;
async fn query_fee_details_opaque(
&self,
extrinsic: Vec<u8>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::FeeDetails>;
async fn query_info<Address, Call, Signature, TransactionExtension>(
&self,
extrinsic: UncheckedExtrinsic<Address, Call, Signature, TransactionExtension>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::RuntimeDispatchInfo>
where
Address: Encode,
Call: Encode,
Signature: Encode,
TransactionExtension: Encode;
async fn query_info_opaque(
&self,
extrinsic: Vec<u8>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::RuntimeDispatchInfo>;
async fn query_length_to_fee(
&self,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance>;
async fn query_weight_to_fee(
&self,
weight: Self::Weight,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance>;
}
#[maybe_async::maybe_async(?Send)]
impl<T, Client> TransactionPaymentApi 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_fee_details<Address, Call, Signature, TransactionExtension>(
&self,
extrinsic: UncheckedExtrinsic<Address, Call, Signature, TransactionExtension>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::FeeDetails>
where
Address: Encode,
Call: Encode,
Signature: Encode,
TransactionExtension: Encode,
{
self.query_fee_details_opaque(extrinsic.encode(), length, at_block).await
}
async fn query_fee_details_opaque(
&self,
extrinsic: Vec<u8>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::FeeDetails> {
self.runtime_call(
"TransactionPaymentApi_query_fee_details",
vec![extrinsic, length.encode()],
at_block,
)
.await
}
async fn query_info<Address, Call, Signature, TransactionExtension>(
&self,
extrinsic: UncheckedExtrinsic<Address, Call, Signature, TransactionExtension>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::RuntimeDispatchInfo>
where
Address: Encode,
Call: Encode,
Signature: Encode,
TransactionExtension: Encode,
{
self.query_info_opaque(extrinsic.encode(), length, at_block).await
}
async fn query_info_opaque(
&self,
extrinsic: Vec<u8>,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::RuntimeDispatchInfo> {
self.runtime_call(
"TransactionPaymentApi_query_info",
vec![extrinsic, length.encode()],
at_block,
)
.await
}
async fn query_length_to_fee(
&self,
length: u32,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance> {
self.runtime_call(
"TransactionPaymentApi_query_length_to_fee",
vec![length.encode()],
at_block,
)
.await
}
async fn query_weight_to_fee(
&self,
weight: Self::Weight,
at_block: Option<Self::Hash>,
) -> Result<Self::Balance> {
self.runtime_call(
"TransactionPaymentApi_query_weight_to_fee",
vec![weight.encode()],
at_block,
)
.await
}
}