subsoil/consensus/aura/
inherents.rs1use crate::inherents::{Error, InherentData, InherentIdentifier};
9
10pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"auraslot";
12
13pub type InherentType = crate::consensus::slots::Slot;
15
16pub trait AuraInherentData {
18 fn aura_inherent_data(&self) -> Result<Option<InherentType>, Error>;
20 fn aura_replace_inherent_data(&mut self, new: InherentType);
22}
23
24impl AuraInherentData for InherentData {
25 fn aura_inherent_data(&self) -> Result<Option<InherentType>, Error> {
26 self.get_data(&INHERENT_IDENTIFIER)
27 }
28
29 fn aura_replace_inherent_data(&mut self, new: InherentType) {
30 self.replace_data(INHERENT_IDENTIFIER, &new);
31 }
32}
33
34#[cfg(feature = "std")]
37pub struct InherentDataProvider {
38 slot: InherentType,
39}
40
41#[cfg(feature = "std")]
42impl InherentDataProvider {
43 pub fn new(slot: InherentType) -> Self {
45 Self { slot }
46 }
47
48 pub fn from_timestamp_and_slot_duration(
51 timestamp: crate::timestamp::Timestamp,
52 slot_duration: crate::consensus::slots::SlotDuration,
53 ) -> Self {
54 let slot = InherentType::from_timestamp(timestamp, slot_duration);
55
56 Self { slot }
57 }
58}
59
60#[cfg(feature = "std")]
61impl core::ops::Deref for InherentDataProvider {
62 type Target = InherentType;
63
64 fn deref(&self) -> &Self::Target {
65 &self.slot
66 }
67}
68
69#[cfg(feature = "std")]
70#[async_trait::async_trait]
71impl crate::inherents::InherentDataProvider for InherentDataProvider {
72 async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
73 inherent_data.put_data(INHERENT_IDENTIFIER, &self.slot)
74 }
75
76 async fn try_handle_error(
77 &self,
78 _: &InherentIdentifier,
79 _: &[u8],
80 ) -> Option<Result<(), Error>> {
81 None
83 }
84}