sequencer/request_response/
request.rs1use anyhow::{Context, Result};
2use async_trait::async_trait;
3use committable::Commitment;
4use espresso_types::{
5 v0_3::{ChainConfig, RewardAccountV1, RewardMerkleTreeV1},
6 v0_4::{RewardAccountV2, RewardMerkleTreeV2},
7 FeeAccount, FeeMerkleTree, Leaf2,
8};
9use hotshot_types::data::VidShare;
10use request_response::{request::Request as RequestTrait, Serializable};
11use serde::{Deserialize, Serialize};
12
13use crate::api::BlocksFrontier;
14
15type Height = u64;
17type ViewNumber = u64;
18type RequestId = u64;
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
23pub enum Request {
24 Accounts(Height, ViewNumber, Vec<FeeAccount>),
26 Leaf(Height),
28 ChainConfig(Commitment<ChainConfig>),
30 BlocksFrontier(Height, ViewNumber),
32 RewardAccountsV2(Height, ViewNumber, Vec<RewardAccountV2>),
34 RewardAccountsV1(Height, ViewNumber, Vec<RewardAccountV1>),
36 VidShare(Height, RequestId),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
43pub enum Response {
44 Accounts(FeeMerkleTree),
46 Leaf(Vec<Leaf2>),
48 ChainConfig(ChainConfig),
50 BlocksFrontier(BlocksFrontier),
52 RewardAccountsV2(RewardMerkleTreeV2),
54 RewardAccountsV1(RewardMerkleTreeV1),
56 VidShare(VidShare),
58}
59
60#[async_trait]
63impl RequestTrait for Request {
64 type Response = Response;
65
66 async fn validate(&self) -> Result<()> {
67 Ok(())
69 }
70}
71
72impl Serializable for Request {
75 fn to_bytes(&self) -> Result<Vec<u8>> {
76 bincode::serialize(&self).with_context(|| "failed to serialize")
77 }
78
79 fn from_bytes(bytes: &[u8]) -> Result<Self> {
80 bincode::deserialize(bytes).with_context(|| "failed to deserialize")
81 }
82}
83
84impl Serializable for Response {
87 fn to_bytes(&self) -> Result<Vec<u8>> {
88 bincode::serialize(self).with_context(|| "failed to serialize")
89 }
90
91 fn from_bytes(bytes: &[u8]) -> Result<Self> {
92 bincode::deserialize(bytes).with_context(|| "failed to deserialize")
93 }
94}