1#![cfg_attr(not(feature = "std"), no_std)]
3
4use domain_runtime_primitives::Balance;
5use parity_scale_codec::{Decode, Encode};
6use sp_inherents::{InherentIdentifier, IsFatalError};
7
8pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"blockfee";
10
11#[derive(Debug, Encode, Decode)]
12pub enum InherentError {
13 IncorrectConsensusChainByteFee,
14}
15
16impl IsFatalError for InherentError {
17 fn is_fatal_error(&self) -> bool {
18 true
19 }
20}
21
22pub type InherentType = Balance;
24
25#[cfg(feature = "std")]
27pub struct InherentDataProvider {
28 data: InherentType,
29}
30
31#[cfg(feature = "std")]
32impl InherentDataProvider {
33 pub fn new(data: InherentType) -> Self {
35 Self { data }
36 }
37
38 pub fn data(&self) -> &InherentType {
40 &self.data
41 }
42}
43
44#[cfg(feature = "std")]
45#[async_trait::async_trait]
46impl sp_inherents::InherentDataProvider for InherentDataProvider {
47 async fn provide_inherent_data(
48 &self,
49 inherent_data: &mut sp_inherents::InherentData,
50 ) -> Result<(), sp_inherents::Error> {
51 inherent_data.put_data(INHERENT_IDENTIFIER, &self.data)
52 }
53
54 async fn try_handle_error(
55 &self,
56 identifier: &InherentIdentifier,
57 error: &[u8],
58 ) -> Option<Result<(), sp_inherents::Error>> {
59 if *identifier != INHERENT_IDENTIFIER {
60 return None;
61 }
62
63 let error = InherentError::decode(&mut &*error).ok()?;
64
65 Some(Err(sp_inherents::Error::Application(Box::from(format!(
66 "{error:?}"
67 )))))
68 }
69}