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::{
14    data::ViewNumber,
15    traits::{node_implementation::NodeType, signature_key::SignatureKey},
16};
17
18#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
19/// A signed request for a proposal.
20pub struct ProposalRequestPayload<TYPES: NodeType> {
21    /// The view number that we're requesting a proposal for.
22    pub view_number: ViewNumber,
23
24    /// Our public key. The ensures that the recipient can reply to
25    /// us directly.
26    pub key: TYPES::SignatureKey,
27}
28
29impl<TYPES: NodeType> Committable for ProposalRequestPayload<TYPES> {
30    fn commit(&self) -> committable::Commitment<Self> {
31        RawCommitmentBuilder::new("signed proposal request commitment")
32            .u64_field("view number", *self.view_number)
33            .var_size_bytes(&self.key.to_bytes())
34            .finalize()
35    }
36}
37
38impl<TYPES: NodeType> std::fmt::Debug for ProposalRequestPayload<TYPES> {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        f.debug_struct("ProposalRequestPayload")
41            .field("view_number", &self.view_number)
42            .field("key", &format_args!("{}", self.key))
43            .finish()
44    }
45}