substrate_api_client/extrinsic/
utility.rs1use crate::{rpc::Request, Api};
22use ac_compose_macros::compose_extrinsic;
23use ac_primitives::{
24 config::Config, extrinsic_params::ExtrinsicParams, extrinsics::CallIndex, SignExtrinsic,
25 UncheckedExtrinsic,
26};
27#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
28use alloc::boxed::Box;
29use alloc::vec::Vec;
30use codec::{Decode, Encode};
31
32const UTILITY_MODULE: &str = "Utility";
33const BATCH: &str = "batch";
34const FORCE_BATCH: &str = "force_batch";
35
36#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
37pub struct Batch<Call> {
38 pub calls: Vec<Call>,
39}
40
41pub type BatchCall<Call> = (CallIndex, Batch<Call>);
42
43#[maybe_async::maybe_async(?Send)]
44pub trait UtilityExtrinsics {
45 type Extrinsic<Call>;
46
47 async fn batch<Call: Encode + Clone>(
49 &self,
50 calls: Vec<Call>,
51 ) -> Option<Self::Extrinsic<BatchCall<Call>>>;
52
53 async fn force_batch<Call: Encode + Clone>(
55 &self,
56 calls: Vec<Call>,
57 ) -> Option<Self::Extrinsic<BatchCall<Call>>>;
58}
59
60#[maybe_async::maybe_async(?Send)]
61impl<T, Client> UtilityExtrinsics for Api<T, Client>
62where
63 T: Config,
64 Client: Request,
65{
66 type Extrinsic<Call> = UncheckedExtrinsic<
67 <T::ExtrinsicSigner as SignExtrinsic<T::AccountId>>::ExtrinsicAddress,
68 Call,
69 <T::ExtrinsicSigner as SignExtrinsic<T::AccountId>>::Signature,
70 <T::ExtrinsicParams as ExtrinsicParams<T::Index, T::Hash>>::TxExtension,
71 >;
72
73 async fn batch<Call: Encode + Clone>(
74 &self,
75 calls: Vec<Call>,
76 ) -> Option<Self::Extrinsic<BatchCall<Call>>> {
77 let calls = Batch { calls };
78 compose_extrinsic!(self, UTILITY_MODULE, BATCH, calls)
79 }
80
81 async fn force_batch<Call: Encode + Clone>(
82 &self,
83 calls: Vec<Call>,
84 ) -> Option<Self::Extrinsic<BatchCall<Call>>> {
85 let calls = Batch { calls };
86 compose_extrinsic!(self, UTILITY_MODULE, FORCE_BATCH, calls)
87 }
88}