cfxcore/sync/message/
get_terminal_block_hashes.rs

1// Copyright 2019 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5use crate::{
6    message::RequestId,
7    sync::{
8        message::{Context, GetTerminalBlockHashesResponse, Handleable},
9        Error,
10    },
11};
12use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
13use rlp_derive::{RlpDecodable, RlpEncodable};
14
15#[derive(Debug, PartialEq, RlpDecodable, RlpEncodable, DeriveMallocSizeOf)]
16pub struct GetTerminalBlockHashes {
17    pub request_id: RequestId,
18}
19
20impl Handleable for GetTerminalBlockHashes {
21    fn handle(self, ctx: &Context) -> Result<(), Error> {
22        let best_info = ctx.manager.graph.consensus.best_info();
23        let terminal_hashes = best_info.bounded_terminal_block_hashes.clone();
24        let response = GetTerminalBlockHashesResponse {
25            request_id: self.request_id,
26            hashes: terminal_hashes,
27        };
28        ctx.send_response(&response)
29    }
30}