sp_block_builder/lib.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! The block builder runtime api.
19
20#![cfg_attr(not(feature = "std"), no_std)]
21
22extern crate alloc;
23
24use sp_inherents::{CheckInherentsResult, InherentData};
25use sp_runtime::{traits::Block as BlockT, ApplyExtrinsicResult};
26#[cfg(feature = "std")]
27mod client_side;
28
29#[cfg(feature = "std")]
30pub use client_side::*;
31
32sp_api::decl_runtime_apis! {
33 /// The `BlockBuilder` api trait that provides the required functionality for building a block.
34 #[api_version(6)]
35 pub trait BlockBuilder {
36 /// Apply the given extrinsic.
37 ///
38 /// Returns an inclusion outcome which specifies if this extrinsic is included in
39 /// this block or not.
40 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult;
41
42 #[changed_in(6)]
43 fn apply_extrinsic(
44 extrinsic: <Block as BlockT>::Extrinsic,
45 ) -> sp_runtime::legacy::byte_sized_error::ApplyExtrinsicResult;
46
47 /// Finish the current block.
48 #[renamed("finalise_block", 3)]
49 fn finalize_block() -> <Block as BlockT>::Header;
50
51 /// Generate inherent extrinsics. The inherent data will vary from chain to chain.
52 fn inherent_extrinsics(
53 inherent: InherentData,
54 ) -> alloc::vec::Vec<<Block as BlockT>::Extrinsic>;
55
56 /// Check that the inherents are valid. The inherent data will vary from chain to chain.
57 fn check_inherents(block: <Block as BlockT>::LazyBlock, data: InherentData) -> CheckInherentsResult;
58 }
59}