pallas_localstate/
queries.rs1use minicbor::{data::Cbor, Decoder};
2use pallas_machines::{primitives::Point, DecodePayload, EncodePayload, PayloadDecoder};
3
4use super::Query;
5
6#[derive(Debug, Clone)]
7pub struct BlockQuery {}
8
9#[derive(Debug, Clone)]
10pub enum RequestV10 {
11 BlockQuery(BlockQuery),
12 GetSystemStart,
13 GetChainBlockNo,
14 GetChainPoint,
15}
16
17impl EncodePayload for RequestV10 {
18 fn encode_payload(
19 &self,
20 e: &mut pallas_machines::PayloadEncoder,
21 ) -> Result<(), Box<dyn std::error::Error>> {
22 match self {
23 Self::BlockQuery(..) => {
24 todo!()
25 }
26 Self::GetSystemStart => {
27 e.u16(1)?;
28 Ok(())
29 }
30 Self::GetChainBlockNo => {
31 e.u16(2)?;
32 Ok(())
33 }
34 Self::GetChainPoint => {
35 e.u16(3)?;
36 Ok(())
37 }
38 }
39 }
40}
41
42impl DecodePayload for RequestV10 {
43 fn decode_payload(
44 _d: &mut pallas_machines::PayloadDecoder,
45 ) -> Result<Self, Box<dyn std::error::Error>> {
46 todo!()
47 }
48}
49
50#[derive(Debug, Clone)]
51pub struct GenericResponse(Vec<u8>);
52
53impl EncodePayload for GenericResponse {
54 fn encode_payload(
55 &self,
56 _e: &mut pallas_machines::PayloadEncoder,
57 ) -> Result<(), Box<dyn std::error::Error>> {
58 todo!()
59 }
60}
61
62impl DecodePayload for GenericResponse {
63 fn decode_payload(
64 d: &mut pallas_machines::PayloadDecoder,
65 ) -> Result<Self, Box<dyn std::error::Error>> {
66 let cbor: Cbor = d.decode()?;
67 let slice = cbor.as_ref();
68 let vec = slice.to_vec();
69 Ok(GenericResponse(vec))
70 }
71}
72
73impl TryInto<Point> for GenericResponse {
74 type Error = Box<dyn std::error::Error>;
75
76 fn try_into(self) -> Result<Point, Self::Error> {
77 let mut d = PayloadDecoder(Decoder::new(self.0.as_slice()));
78 Point::decode_payload(&mut d)
79 }
80}
81
82#[derive(Debug, Clone)]
83pub struct QueryV10 {}
84
85impl Query for QueryV10 {
86 type Request = RequestV10;
87 type Response = GenericResponse;
88}