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
24#[cfg(feature = "std")]
25mod client_side;
26
27#[cfg(feature = "std")]
28pub use client_side::*;
29
30use sp_inherents::{CheckInherentsResult, InherentData};
31use sp_runtime::{traits::Block as BlockT, ApplyExtrinsicResult};
32
33sp_api::decl_runtime_apis! {
34 /// The `BlockBuilder` api trait that provides the required functionality for building a block.
35 #[api_version(6)]
36 pub trait BlockBuilder {
37 /// Apply the given extrinsic.
38 ///
39 /// Returns an inclusion outcome which specifies if this extrinsic is included in
40 /// this block or not.
41 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult;
42
43 #[changed_in(6)]
44 fn apply_extrinsic(
45 extrinsic: <Block as BlockT>::Extrinsic,
46 ) -> sp_runtime::legacy::byte_sized_error::ApplyExtrinsicResult;
47
48 /// Finish the current block.
49 #[renamed("finalise_block", 3)]
50 fn finalize_block() -> <Block as BlockT>::Header;
51
52 /// Generate inherent extrinsics. The inherent data will vary from chain to chain.
53 fn inherent_extrinsics(
54 inherent: InherentData,
55 ) -> alloc::vec::Vec<<Block as BlockT>::Extrinsic>;
56
57 /// Check that the inherents are valid. The inherent data will vary from chain to chain.
58 fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult;
59 }
60}