avail_rust_core/
consensus.rs1use crate::substrate::sp_core::vrf::VrfSignature;
2use codec::{Decode, Encode};
3pub use subxt_core::config::substrate::ConsensusEngineId;
4
5pub mod babe {
6 use super::*;
7
8 pub const BABE_ENGINE_ID: ConsensusEngineId = *b"BABE";
10
11 #[derive(Clone, Encode, Decode, Debug)]
13 pub struct PrimaryPreDigest {
14 pub authority_index: u32,
16 pub slot: u64,
18 pub vrf_signature: VrfSignature,
20 }
21
22 #[derive(Clone, Encode, Decode, Debug)]
24 pub struct SecondaryPlainPreDigest {
25 pub authority_index: u32,
32 pub slot: u64,
34 }
35
36 #[derive(Clone, Encode, Decode, Debug)]
38 pub struct SecondaryVRFPreDigest {
39 pub authority_index: u32,
41 pub slot: u64,
43 pub vrf_signature: VrfSignature,
45 }
46
47 #[derive(Clone, Encode, Decode, Debug)]
51 pub enum PreDigest {
52 #[codec(index = 1)]
54 Primary(PrimaryPreDigest),
55 #[codec(index = 2)]
57 SecondaryPlain(SecondaryPlainPreDigest),
58 #[codec(index = 3)]
60 SecondaryVRF(SecondaryVRFPreDigest),
61 }
62
63 impl PreDigest {
64 pub fn authority_index(&self) -> u32 {
66 match self {
67 PreDigest::Primary(primary) => primary.authority_index,
68 PreDigest::SecondaryPlain(secondary) => secondary.authority_index,
69 PreDigest::SecondaryVRF(secondary) => secondary.authority_index,
70 }
71 }
72
73 pub fn slot(&self) -> u64 {
75 match self {
76 PreDigest::Primary(primary) => primary.slot,
77 PreDigest::SecondaryPlain(secondary) => secondary.slot,
78 PreDigest::SecondaryVRF(secondary) => secondary.slot,
79 }
80 }
81
82 pub fn is_primary(&self) -> bool {
84 matches!(self, PreDigest::Primary(..))
85 }
86
87 pub fn vrf_signature(&self) -> Option<&VrfSignature> {
89 match self {
90 PreDigest::Primary(primary) => Some(&primary.vrf_signature),
91 PreDigest::SecondaryVRF(secondary) => Some(&secondary.vrf_signature),
92 PreDigest::SecondaryPlain(_) => None,
93 }
94 }
95 }
96}