snarkos_node_router_messages/
puzzle_request.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkOS library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17
18use snarkvm::prelude::{FromBytes, ToBytes};
19
20use std::borrow::Cow;
21
22#[derive(Clone, Debug, PartialEq, Eq)]
23pub struct PuzzleRequest;
24
25impl MessageTrait for PuzzleRequest {
26    /// Returns the message name.
27    #[inline]
28    fn name(&self) -> Cow<'static, str> {
29        "PuzzleRequest".into()
30    }
31}
32
33impl ToBytes for PuzzleRequest {
34    fn write_le<W: io::Write>(&self, _writer: W) -> io::Result<()> {
35        Ok(())
36    }
37}
38
39impl FromBytes for PuzzleRequest {
40    fn read_le<R: io::Read>(_reader: R) -> io::Result<Self> {
41        Ok(Self)
42    }
43}
44
45#[cfg(test)]
46pub mod tests {
47    use crate::PuzzleRequest;
48    use snarkvm::utilities::{FromBytes, ToBytes};
49
50    use bytes::{Buf, BufMut, BytesMut};
51
52    #[test]
53    fn puzzle_request_roundtrip() {
54        let puzzle_request = PuzzleRequest;
55        let mut bytes = BytesMut::default().writer();
56        puzzle_request.write_le(&mut bytes).unwrap();
57        let decoded = PuzzleRequest::read_le(&mut bytes.into_inner().reader()).unwrap();
58        assert_eq!(decoded, puzzle_request);
59    }
60}