mithril_aggregator/entities/
signer_registration_message.rs

1use mithril_common::entities::{Epoch, PartyId, SignerWithStake, Stake};
2use serde::{Deserialize, Serialize};
3
4/// Message structure of signer registrations for an epoch.
5#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
6pub struct SignerRegistrationsMessage {
7    /// The epoch at which the registration was sent.
8    pub registered_at: Epoch,
9
10    /// The epoch at which the registration was able to send signatures.
11    pub signing_at: Epoch,
12
13    /// The signer registrations
14    pub registrations: Vec<SignerRegistrationsListItemMessage>,
15}
16
17/// Message structure of a signer registration
18#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
19pub struct SignerRegistrationsListItemMessage {
20    /// The registered signer party id
21    pub party_id: PartyId,
22
23    /// The registered signer stake
24    pub stake: Stake,
25}
26
27impl SignerRegistrationsMessage {
28    /// Build a [SignerRegistrationsMessage] from a list of signers with stake.
29    pub fn new(registered_at: Epoch, signers_with_stake: Vec<SignerWithStake>) -> Self {
30        let registrations: Vec<SignerRegistrationsListItemMessage> = signers_with_stake
31            .into_iter()
32            .map(|signer| SignerRegistrationsListItemMessage {
33                party_id: signer.party_id,
34                stake: signer.stake,
35            })
36            .collect();
37
38        Self {
39            registered_at,
40            signing_at: registered_at.offset_to_signer_signing_offset(),
41            registrations,
42        }
43    }
44}