tp_block_builder/lib.rs
1// This file is part of Tetcore.
2
3// Copyright (C) 2019-2021 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
22use tp_runtime::{traits::Block as BlockT, ApplyExtrinsicResult};
23
24use tp_inherents::{InherentData, CheckInherentsResult};
25
26tp_api::decl_runtime_apis! {
27 /// The `BlockBuilder` api trait that provides the required functionality for building a block.
28 #[api_version(4)]
29 pub trait BlockBuilder {
30 /// Apply the given extrinsic.
31 ///
32 /// Returns an inclusion outcome which specifies if this extrinsic is included in
33 /// this block or not.
34 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult;
35 /// Finish the current block.
36 #[renamed("finalise_block", 3)]
37 fn finalize_block() -> <Block as BlockT>::Header;
38 /// Generate inherent extrinsics. The inherent data will vary from chain to chain.
39 fn inherent_extrinsics(
40 inherent: InherentData,
41 ) -> tetcore_std::vec::Vec<<Block as BlockT>::Extrinsic>;
42 /// Check that the inherents are valid. The inherent data will vary from chain to chain.
43 fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult;
44 /// Generate a random seed.
45 fn random_seed() -> <Block as BlockT>::Hash;
46 }
47}