sc_basic_authorship/lib.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Basic implementation of block-authoring logic.
20//!
21//! # Example
22//!
23//! ```
24//! # use sc_basic_authorship::ProposerFactory;
25//! # use sp_consensus::{Environment, Proposer};
26//! # use sp_runtime::generic::BlockId;
27//! # use std::{sync::Arc, time::Duration};
28//! # use substrate_test_runtime_client::{
29//! # runtime::Transfer, Sr25519Keyring,
30//! # DefaultTestClientBuilderExt, TestClientBuilderExt,
31//! # };
32//! # use sc_transaction_pool::{BasicPool, FullChainApi};
33//! # let client = Arc::new(substrate_test_runtime_client::new());
34//! # let spawner = sp_core::testing::TaskExecutor::new();
35//! # let txpool = Arc::from(BasicPool::new_full(
36//! # Default::default(),
37//! # true.into(),
38//! # None,
39//! # spawner.clone(),
40//! # client.clone(),
41//! # ));
42//! // The first step is to create a `ProposerFactory`.
43//! let mut proposer_factory = ProposerFactory::new(
44//! spawner,
45//! client.clone(),
46//! txpool.clone(),
47//! None,
48//! None,
49//! );
50//!
51//! // From this factory, we create a `Proposer`.
52//! let proposer = proposer_factory.init(
53//! &client.header(client.chain_info().genesis_hash).unwrap().unwrap(),
54//! );
55//!
56//! // The proposer is created asynchronously.
57//! let proposer = futures::executor::block_on(proposer).unwrap();
58//!
59//! // This `Proposer` allows us to create a block proposition.
60//! // The proposer will grab transactions from the transaction pool, and put them into the block.
61//! let future = proposer.propose(
62//! Default::default(),
63//! Default::default(),
64//! Duration::from_secs(2),
65//! None,
66//! );
67//!
68//! // We wait until the proposition is performed.
69//! let block = futures::executor::block_on(future).unwrap();
70//! println!("Generated block: {:?}", block.block);
71//! ```
72
73mod basic_authorship;
74
75pub use crate::basic_authorship::{Proposer, ProposerFactory, DEFAULT_BLOCK_SIZE_LIMIT};