substrate_api_client/api/runtime_api/
block_builder.rsuse super::{RuntimeApi, RuntimeApiClient};
use crate::{api::Result, rpc::Request};
use ac_primitives::{config::Config, UncheckedExtrinsicV4};
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use alloc::{vec, vec::Vec};
use sp_core::{Bytes, Encode};
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_runtime::ApplyExtrinsicResult;
#[maybe_async::maybe_async(?Send)]
pub trait BlockBuilderApi: RuntimeApi {
type ApplyExtrinsicResult;
type Block;
type InherentData;
type CheckInherentsResult;
type Header;
async fn apply_extrinsic<Address, Call, Signature, SignedExtra>(
&self,
extrinsic: UncheckedExtrinsicV4<Address, Call, Signature, SignedExtra>,
at_block: Option<Self::Hash>,
) -> Result<Self::ApplyExtrinsicResult>
where
Address: Encode,
Call: Encode,
Signature: Encode,
SignedExtra: Encode;
async fn apply_opaque_extrinsic(
&self,
extrinsic: Vec<u8>,
at_block: Option<Self::Hash>,
) -> Result<Self::ApplyExtrinsicResult>;
async fn check_inherents(
&self,
block: Self::Block,
data: Self::InherentData,
at_block: Option<Self::Hash>,
) -> Result<Self::CheckInherentsResult>;
async fn finalize_block(&self, at_block: Option<Self::Hash>) -> Result<Self::Header>;
async fn inherent_extrinsics(
&self,
inherent: Self::InherentData,
at_block: Option<Self::Hash>,
) -> Result<Vec<Bytes>>;
}
#[maybe_async::maybe_async(?Send)]
impl<T, Client> BlockBuilderApi for RuntimeApiClient<T, Client>
where
T: Config,
Client: Request,
{
type ApplyExtrinsicResult = ApplyExtrinsicResult;
type Block = T::Block;
type InherentData = InherentData;
type CheckInherentsResult = CheckInherentsResult;
type Header = T::Header;
async fn apply_extrinsic<Address, Call, Signature, SignedExtra>(
&self,
extrinsic: UncheckedExtrinsicV4<Address, Call, Signature, SignedExtra>,
at_block: Option<Self::Hash>,
) -> Result<Self::ApplyExtrinsicResult>
where
Address: Encode,
Call: Encode,
Signature: Encode,
SignedExtra: Encode,
{
self.apply_opaque_extrinsic(extrinsic.encode(), at_block).await
}
async fn apply_opaque_extrinsic(
&self,
extrinsic: Vec<u8>,
at_block: Option<Self::Hash>,
) -> Result<Self::ApplyExtrinsicResult> {
self.runtime_call("BlockBuilder_apply_extrinsic", vec![extrinsic], at_block)
.await
}
async fn check_inherents(
&self,
block: Self::Block,
data: Self::InherentData,
at_block: Option<Self::Hash>,
) -> Result<Self::CheckInherentsResult> {
self.runtime_call(
"BlockBuilder_check_inherents",
vec![block.encode(), data.encode()],
at_block,
)
.await
}
async fn finalize_block(&self, at_block: Option<Self::Hash>) -> Result<Self::Header> {
self.runtime_call("BlockBuilder_finalize_block", vec![], at_block).await
}
async fn inherent_extrinsics(
&self,
inherent: Self::InherentData,
at_block: Option<Self::Hash>,
) -> Result<Vec<Bytes>> {
self.runtime_call("BlockBuilder_inherent_extrinsics", vec![inherent.encode()], at_block)
.await
}
}