1
// Copyright Moonsong Labs
2
// This file is part of Moonkit.
3

            
4
// Moonkit is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonkit is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Moonkit.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
use sp_inherents::{InherentData, InherentIdentifier};
18

            
19
/// The InherentIdentifier for nimbus's author inherent
20
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"author__";
21

            
22
/// A bare minimum inherent data provider that provides no real data.
23
/// The inherent is simply used as a way to kick off some computation
24
/// until https://github.com/paritytech/substrate/pull/10128 lands.
25
pub struct InherentDataProvider;
26

            
27
#[cfg(feature = "std")]
28
#[async_trait::async_trait]
29
impl sp_inherents::InherentDataProvider for InherentDataProvider {
30
	async fn provide_inherent_data(
31
		&self,
32
		inherent_data: &mut InherentData,
33
	) -> Result<(), sp_inherents::Error> {
34
		inherent_data.put_data(INHERENT_IDENTIFIER, &())
35
	}
36

            
37
	async fn try_handle_error(
38
		&self,
39
		identifier: &InherentIdentifier,
40
		_error: &[u8],
41
	) -> Option<Result<(), sp_inherents::Error>> {
42
		// Dont' process modules from other inherents
43
		if *identifier != INHERENT_IDENTIFIER {
44
			return None;
45
		}
46

            
47
		// All errors with the author inehrent are fatal
48
		Some(Err(sp_inherents::Error::Application(Box::from(
49
			String::from("Error processing dummy nimbus inherent"),
50
		))))
51
	}
52
}