use crate::{rpc::Request, Api};
use ac_compose_macros::compose_extrinsic;
use ac_primitives::{
config::Config, extrinsic_params::ExtrinsicParams, extrinsics::CallIndex, SignExtrinsic,
UncheckedExtrinsic,
};
#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
use alloc::boxed::Box;
use alloc::vec::Vec;
use codec::{Decode, Encode};
const UTILITY_MODULE: &str = "Utility";
const BATCH: &str = "batch";
const FORCE_BATCH: &str = "force_batch";
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub struct Batch<Call> {
pub calls: Vec<Call>,
}
pub type BatchCall<Call> = (CallIndex, Batch<Call>);
#[maybe_async::maybe_async(?Send)]
pub trait UtilityExtrinsics {
type Extrinsic<Call>;
async fn batch<Call: Encode + Clone>(
&self,
calls: Vec<Call>,
) -> Option<Self::Extrinsic<BatchCall<Call>>>;
async fn force_batch<Call: Encode + Clone>(
&self,
calls: Vec<Call>,
) -> Option<Self::Extrinsic<BatchCall<Call>>>;
}
#[maybe_async::maybe_async(?Send)]
impl<T, Client> UtilityExtrinsics for Api<T, Client>
where
T: Config,
Client: Request,
{
type Extrinsic<Call> = UncheckedExtrinsic<
<T::ExtrinsicSigner as SignExtrinsic<T::AccountId>>::ExtrinsicAddress,
Call,
<T::ExtrinsicSigner as SignExtrinsic<T::AccountId>>::Signature,
<T::ExtrinsicParams as ExtrinsicParams<T::Index, T::Hash>>::TxExtension,
>;
async fn batch<Call: Encode + Clone>(
&self,
calls: Vec<Call>,
) -> Option<Self::Extrinsic<BatchCall<Call>>> {
let calls = Batch { calls };
compose_extrinsic!(self, UTILITY_MODULE, BATCH, calls)
}
async fn force_batch<Call: Encode + Clone>(
&self,
calls: Vec<Call>,
) -> Option<Self::Extrinsic<BatchCall<Call>>> {
let calls = Batch { calls };
compose_extrinsic!(self, UTILITY_MODULE, FORCE_BATCH, calls)
}
}