substrate_api_client/api/runtime_api/
api_core.rs1use super::{RuntimeApi, RuntimeApiClient};
15use crate::{api::Result, rpc::Request};
16use ac_primitives::{config::Config, RuntimeVersion};
17#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
18use alloc::boxed::Box;
19use alloc::vec;
20use sp_core::{Bytes, Encode};
21
22#[maybe_async::maybe_async(?Send)]
23pub trait CoreApi: RuntimeApi {
24 type Block;
25 type Header;
26 type RuntimeVersion;
27
28 async fn execute_block(&self, block: Self::Block, at_block: Option<Self::Hash>) -> Result<()>;
30
31 async fn execute_opaque_block(&self, block: Bytes, at_block: Option<Self::Hash>) -> Result<()>;
33
34 async fn initialize_block(
36 &self,
37 header: Self::Header,
38 at_block: Option<Self::Hash>,
39 ) -> Result<()>;
40
41 async fn version(&self, at_block: Option<Self::Hash>) -> Result<Self::RuntimeVersion>;
43}
44
45#[maybe_async::maybe_async(?Send)]
46impl<T, Client> CoreApi for RuntimeApiClient<T, Client>
47where
48 T: Config,
49 Client: Request,
50{
51 type Block = T::Block;
52 type Header = T::Header;
53 type RuntimeVersion = RuntimeVersion;
54
55 async fn execute_block(&self, block: Self::Block, at_block: Option<Self::Hash>) -> Result<()> {
56 self.execute_opaque_block(block.encode().into(), at_block).await
57 }
58
59 async fn execute_opaque_block(&self, block: Bytes, at_block: Option<Self::Hash>) -> Result<()> {
60 self.runtime_call("Core_execute_block", vec![block.0], at_block).await
61 }
62
63 async fn initialize_block(
64 &self,
65 header: Self::Header,
66 at_block: Option<Self::Hash>,
67 ) -> Result<()> {
68 self.runtime_call("Core_initialize_block", vec![header.encode()], at_block)
69 .await
70 }
71
72 async fn version(&self, at_block: Option<Self::Hash>) -> Result<Self::RuntimeVersion> {
73 self.runtime_call("Core_version", vec![], at_block).await
74 }
75}