hotshot_query_service/fetching/
request.rs1use std::{fmt::Debug, hash::Hash};
16
17use derive_more::{From, Into};
18use hotshot_types::{
19 data::{VidCommitment, VidCommon},
20 traits::node_implementation::NodeType,
21};
22
23use crate::{
24 Payload,
25 availability::{BlockQueryData, Certificate2, LeafQueryData, VidCommonQueryData},
26 fetching::NonEmptyRange,
27};
28
29pub trait Request<Types>: Copy + Debug + Eq + Hash + Send {
31 type Response: Clone + Send;
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
37pub struct PayloadRequest(pub VidCommitment);
38
39impl<Types: NodeType> Request<Types> for PayloadRequest {
40 type Response = Payload<Types>;
41}
42
43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, From, Into)]
45pub struct BlockRangeRequest {
46 pub start: u64,
47 pub end: u64,
48}
49
50impl<Types: NodeType> Request<Types> for BlockRangeRequest {
51 type Response = NonEmptyRange<BlockQueryData<Types>>;
52}
53
54#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
56pub struct VidCommonRequest(pub VidCommitment);
57
58impl<Types: NodeType> Request<Types> for VidCommonRequest {
59 type Response = VidCommon;
60}
61
62#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, From, Into)]
64pub struct VidCommonRangeRequest {
65 pub start: u64,
66 pub end: u64,
67}
68
69impl<Types: NodeType> Request<Types> for VidCommonRangeRequest {
70 type Response = NonEmptyRange<VidCommonQueryData<Types>>;
71}
72
73#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, From, Into)]
75pub struct LeafRequest {
76 pub height: u64,
77}
78
79impl LeafRequest {
80 pub fn new(height: u64) -> Self {
81 Self { height }
82 }
83}
84
85impl<Types: NodeType> Request<Types> for LeafRequest {
86 type Response = LeafQueryData<Types>;
87}
88
89#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
91pub struct LeafRangeRequest {
92 pub start: u64,
94
95 pub end: u64,
97}
98
99impl<Types: NodeType> Request<Types> for LeafRangeRequest {
100 type Response = NonEmptyRange<LeafQueryData<Types>>;
101}
102
103#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
107pub struct Certificate2Request {
108 pub height: u64,
109}
110
111impl<Types: NodeType> Request<Types> for Certificate2Request {
112 type Response = Option<Certificate2<Types>>;
113}