jam_std_common/safrole/
mod.rs1use crate::{bandersnatch, ed25519, Entropy, EpochPeriod, ValKeyset};
4use jam_types::{BoundedVec, FixedVec, Slot};
5use scale::{Decode, Encode, MaxEncodedLen};
6
7pub mod ticket;
8
9pub type EpochIndex = Slot;
11
12pub type EpochKeys = FixedVec<EpochKeySet, jam_types::ValCount>;
13pub type FallbackKeys = FixedVec<bandersnatch::Public, EpochPeriod>;
14pub type EpochTickets = FixedVec<ticket::TicketBody, EpochPeriod>;
15pub type EpochTicketsAccumulator = BoundedVec<ticket::TicketBody, EpochPeriod>;
16
17#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)]
19pub struct EpochKeySet {
20 pub bandersnatch: bandersnatch::Public,
22 pub ed25519: ed25519::Public,
24}
25
26impl From<&ValKeyset> for EpochKeySet {
27 fn from(keyset: &ValKeyset) -> Self {
28 Self { bandersnatch: keyset.bandersnatch, ed25519: keyset.ed25519 }
29 }
30}
31
32#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)]
36pub struct NextEpochDescriptor {
37 pub entropy: Entropy,
39 pub tickets_entropy: Entropy,
41 pub validators: EpochKeys,
43}
44
45#[derive(Encode, Decode, Debug, Clone)]
46pub enum TicketOrKey {
47 Ticket(ticket::TicketBody),
48 Key(bandersnatch::Public),
49}
50
51impl TicketOrKey {
52 pub fn ticket(self) -> Option<ticket::TicketBody> {
53 match self {
54 TicketOrKey::Ticket(t) => Some(t),
55 TicketOrKey::Key(_) => None,
56 }
57 }
58}
59
60#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq)]
61pub enum TicketsOrKeys {
62 Tickets(EpochTickets),
63 Keys(FallbackKeys),
64}
65
66impl TicketsOrKeys {
67 pub fn tickets(&self) -> Option<&EpochTickets> {
68 match self {
69 Self::Tickets(t) => Some(t),
70 Self::Keys(_) => None,
71 }
72 }
73 pub fn get(&self, i: Slot) -> Option<TicketOrKey> {
74 Some(match self {
75 Self::Tickets(t) => TicketOrKey::Ticket(*t.get(i as usize)?),
76 Self::Keys(k) => TicketOrKey::Key(*k.get(i as usize)?),
77 })
78 }
79}