hotshot_types/
request_response.rs

1// Copyright (c) 2021-2024 Espresso Systems (espressosys.com)
2// This file is part of the HotShot repository.
3
4// You should have received a copy of the MIT License
5// along with the HotShot repository. If not, see <https://mit-license.org/>.
6
7//! Types for the request/response implementations. This module incorporates all
8//! of the shared types for all of the network backends.
9
10use committable::{Committable, RawCommitmentBuilder};
11use serde::{Deserialize, Serialize};
12
13use crate::traits::{node_implementation::NodeType, signature_key::SignatureKey};
14
15#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
16/// A signed request for a proposal.
17pub struct ProposalRequestPayload<TYPES: NodeType> {
18    /// The view number that we're requesting a proposal for.
19    pub view_number: TYPES::View,
20
21    /// Our public key. The ensures that the recipient can reply to
22    /// us directly.
23    pub key: TYPES::SignatureKey,
24}
25
26impl<TYPES: NodeType> Committable for ProposalRequestPayload<TYPES> {
27    fn commit(&self) -> committable::Commitment<Self> {
28        RawCommitmentBuilder::new("signed proposal request commitment")
29            .u64_field("view number", *self.view_number)
30            .var_size_bytes(&self.key.to_bytes())
31            .finalize()
32    }
33}
34
35impl<TYPES: NodeType> std::fmt::Debug for ProposalRequestPayload<TYPES> {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        f.debug_struct("ProposalRequestPayload")
38            .field("view_number", &self.view_number)
39            .field("key", &format_args!("{}", self.key))
40            .finish()
41    }
42}