sp_consensus_aura/
inherents.rs1use sp_inherents::{Error, InherentData, InherentIdentifier};
20
21pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"auraslot";
23
24pub type InherentType = sp_consensus_slots::Slot;
26
27pub trait AuraInherentData {
29 fn aura_inherent_data(&self) -> Result<Option<InherentType>, Error>;
31 fn aura_replace_inherent_data(&mut self, new: InherentType);
33}
34
35impl AuraInherentData for InherentData {
36 fn aura_inherent_data(&self) -> Result<Option<InherentType>, Error> {
37 self.get_data(&INHERENT_IDENTIFIER)
38 }
39
40 fn aura_replace_inherent_data(&mut self, new: InherentType) {
41 self.replace_data(INHERENT_IDENTIFIER, &new);
42 }
43}
44
45#[cfg(feature = "std")]
48pub struct InherentDataProvider {
49 slot: InherentType,
50}
51
52#[cfg(feature = "std")]
53impl InherentDataProvider {
54 pub fn new(slot: InherentType) -> Self {
56 Self { slot }
57 }
58
59 pub fn from_timestamp_and_slot_duration(
62 timestamp: sp_timestamp::Timestamp,
63 slot_duration: sp_consensus_slots::SlotDuration,
64 ) -> Self {
65 let slot = InherentType::from_timestamp(timestamp, slot_duration);
66
67 Self { slot }
68 }
69}
70
71#[cfg(feature = "std")]
72impl core::ops::Deref for InherentDataProvider {
73 type Target = InherentType;
74
75 fn deref(&self) -> &Self::Target {
76 &self.slot
77 }
78}
79
80#[cfg(feature = "std")]
81#[async_trait::async_trait]
82impl sp_inherents::InherentDataProvider for InherentDataProvider {
83 async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
84 inherent_data.put_data(INHERENT_IDENTIFIER, &self.slot)
85 }
86
87 async fn try_handle_error(
88 &self,
89 _: &InherentIdentifier,
90 _: &[u8],
91 ) -> Option<Result<(), Error>> {
92 None
94 }
95}