substrate_api_client/api/runtime_api/
block_builder.rs1use super::{RuntimeApi, RuntimeApiClient};
15use crate::{api::Result, rpc::Request};
16use ac_primitives::{config::Config, UncheckedExtrinsic};
17#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
18use alloc::boxed::Box;
19use alloc::{vec, vec::Vec};
20use sp_core::{Bytes, Encode};
21use sp_inherents::{CheckInherentsResult, InherentData};
22use sp_runtime::ApplyExtrinsicResult;
23
24#[maybe_async::maybe_async(?Send)]
25pub trait BlockBuilderApi: RuntimeApi {
26 type ApplyExtrinsicResult;
27 type Block;
28 type InherentData;
29 type CheckInherentsResult;
30 type Header;
31
32 async fn apply_extrinsic<Address, Call, Signature, TransactionExtension>(
34 &self,
35 extrinsic: UncheckedExtrinsic<Address, Call, Signature, TransactionExtension>,
36 at_block: Option<Self::Hash>,
37 ) -> Result<Self::ApplyExtrinsicResult>
38 where
39 Address: Encode,
40 Call: Encode,
41 Signature: Encode,
42 TransactionExtension: Encode;
43
44 async fn apply_opaque_extrinsic(
46 &self,
47 extrinsic: Vec<u8>,
48 at_block: Option<Self::Hash>,
49 ) -> Result<Self::ApplyExtrinsicResult>;
50
51 async fn check_inherents(
53 &self,
54 block: Self::Block,
55 data: Self::InherentData,
56 at_block: Option<Self::Hash>,
57 ) -> Result<Self::CheckInherentsResult>;
58
59 async fn finalize_block(&self, at_block: Option<Self::Hash>) -> Result<Self::Header>;
61
62 async fn inherent_extrinsics(
64 &self,
65 inherent: Self::InherentData,
66 at_block: Option<Self::Hash>,
67 ) -> Result<Vec<Bytes>>;
68}
69
70#[maybe_async::maybe_async(?Send)]
71impl<T, Client> BlockBuilderApi for RuntimeApiClient<T, Client>
72where
73 T: Config,
74 Client: Request,
75{
76 type ApplyExtrinsicResult = ApplyExtrinsicResult;
77 type Block = T::Block;
78 type InherentData = InherentData;
79 type CheckInherentsResult = CheckInherentsResult;
80 type Header = T::Header;
81
82 async fn apply_extrinsic<Address, Call, Signature, TransactionExtension>(
83 &self,
84 extrinsic: UncheckedExtrinsic<Address, Call, Signature, TransactionExtension>,
85 at_block: Option<Self::Hash>,
86 ) -> Result<Self::ApplyExtrinsicResult>
87 where
88 Address: Encode,
89 Call: Encode,
90 Signature: Encode,
91 TransactionExtension: Encode,
92 {
93 self.apply_opaque_extrinsic(extrinsic.encode(), at_block).await
94 }
95
96 async fn apply_opaque_extrinsic(
97 &self,
98 extrinsic: Vec<u8>,
99 at_block: Option<Self::Hash>,
100 ) -> Result<Self::ApplyExtrinsicResult> {
101 self.runtime_call("BlockBuilder_apply_extrinsic", vec![extrinsic], at_block)
102 .await
103 }
104
105 async fn check_inherents(
106 &self,
107 block: Self::Block,
108 data: Self::InherentData,
109 at_block: Option<Self::Hash>,
110 ) -> Result<Self::CheckInherentsResult> {
111 self.runtime_call(
112 "BlockBuilder_check_inherents",
113 vec![block.encode(), data.encode()],
114 at_block,
115 )
116 .await
117 }
118
119 async fn finalize_block(&self, at_block: Option<Self::Hash>) -> Result<Self::Header> {
120 self.runtime_call("BlockBuilder_finalize_block", vec![], at_block).await
121 }
122
123 async fn inherent_extrinsics(
124 &self,
125 inherent: Self::InherentData,
126 at_block: Option<Self::Hash>,
127 ) -> Result<Vec<Bytes>> {
128 self.runtime_call("BlockBuilder_inherent_extrinsics", vec![inherent.encode()], at_block)
129 .await
130 }
131}