mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 15:41:02 +00:00
Move inherents to primitives (#4126)
* Split Aura and Timestamp inherents out of paint * fixup node depedencies * move babe inherents to primitives * move authorship inherents into primitives * Move finalty tracker inherents into primitives * fix aura primitives import
This commit is contained in:
committed by
GitHub
parent
5979a8c3e5
commit
303843f483
@@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features =
|
||||
inherents = { package = "substrate-inherents", path = "../../primitives/inherents", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../../primitives/sr-std", default-features = false }
|
||||
sr-primitives = { path = "../../primitives/sr-primitives", default-features = false }
|
||||
sp-finality-tracker = { path = "../../primitives/finality-tracker", default-features = false }
|
||||
support = { package = "paint-support", path = "../support", default-features = false }
|
||||
paint-system = { path = "../system", default-features = false }
|
||||
impl-trait-for-tuples = "0.1.3"
|
||||
@@ -27,5 +28,6 @@ std = [
|
||||
"support/std",
|
||||
"sr-primitives/std",
|
||||
"paint-system/std",
|
||||
"sp-finality-tracker/std",
|
||||
"inherents/std",
|
||||
]
|
||||
|
||||
@@ -21,64 +21,10 @@
|
||||
use inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError};
|
||||
use sr_primitives::traits::{One, Zero, SaturatedConversion};
|
||||
use rstd::{prelude::*, result, cmp, vec};
|
||||
use codec::Decode;
|
||||
use support::{decl_module, decl_storage};
|
||||
use support::traits::Get;
|
||||
use paint_system::{ensure_none, Trait as SystemTrait};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use codec::Encode;
|
||||
|
||||
/// The identifier for the `finalnum` inherent.
|
||||
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"finalnum";
|
||||
|
||||
/// Auxiliary trait to extract finalized inherent data.
|
||||
pub trait FinalizedInherentData<N: Decode> {
|
||||
/// Get finalized inherent data.
|
||||
fn finalized_number(&self) -> Result<N, inherents::Error>;
|
||||
}
|
||||
|
||||
impl<N: Decode> FinalizedInherentData<N> for InherentData {
|
||||
fn finalized_number(&self) -> Result<N, inherents::Error> {
|
||||
self.get_data(&INHERENT_IDENTIFIER)
|
||||
.and_then(|r| r.ok_or_else(|| "Finalized number inherent data not found".into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for inherent data.
|
||||
#[cfg(feature = "std")]
|
||||
pub struct InherentDataProvider<F, N> {
|
||||
inner: F,
|
||||
_marker: std::marker::PhantomData<N>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<F, N> InherentDataProvider<F, N> {
|
||||
pub fn new(final_oracle: F) -> Self {
|
||||
InherentDataProvider { inner: final_oracle, _marker: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<F, N: Encode> inherents::ProvideInherentData for InherentDataProvider<F, N>
|
||||
where F: Fn() -> Result<N, inherents::Error>
|
||||
{
|
||||
fn inherent_identifier(&self) -> &'static InherentIdentifier {
|
||||
&INHERENT_IDENTIFIER
|
||||
}
|
||||
|
||||
fn provide_inherent_data(
|
||||
&self,
|
||||
inherent_data: &mut InherentData,
|
||||
) -> Result<(), inherents::Error> {
|
||||
(self.inner)()
|
||||
.and_then(|n| inherent_data.put_data(INHERENT_IDENTIFIER, &n))
|
||||
}
|
||||
|
||||
fn error_to_string(&self, _error: &[u8]) -> Option<String> {
|
||||
Some(format!("no further information"))
|
||||
}
|
||||
}
|
||||
use sp_finality_tracker::{INHERENT_IDENTIFIER, FinalizedInherentData};
|
||||
|
||||
pub const DEFAULT_WINDOW_SIZE: u32 = 101;
|
||||
pub const DEFAULT_REPORT_LATENCY: u32 = 1000;
|
||||
|
||||
Reference in New Issue
Block a user