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