OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
uhs/atomizer/archiver/client.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include "client.hpp"
7
10
11#include <utility>
12
13namespace cbdc::archiver {
15 std::shared_ptr<logging::log> logger)
16 : m_endpoint(std::move(endpoint)),
17 m_logger(std::move(logger)) {}
18
19 auto client::init() -> bool {
20 return m_sock.connect(m_endpoint);
21 }
22
23 auto client::get_block(uint64_t height)
24 -> std::optional<cbdc::atomizer::block> {
25 m_logger->info("Requesting block", height, "from archiver...");
26 if(!m_sock.send(height)) {
27 m_logger->error("Error requesting block from archiver.");
28 return std::nullopt;
29 }
30
31 m_logger->info("Waiting for archiver response...");
32 cbdc::buffer resp_pkt;
33 if(!m_sock.receive(resp_pkt)) {
34 m_logger->error("Error receiving block from archiver.");
35 return std::nullopt;
36 }
37
38 auto resp = cbdc::from_buffer<response>(resp_pkt);
39 if(!resp.has_value()) {
40 m_logger->error("Invalid response packet");
41 return std::nullopt;
42 }
43
44 return resp.value();
45 }
46}
auto init() -> bool
Attempts to connect to the archiver.
auto get_block(uint64_t height) -> std::optional< cbdc::atomizer::block >
Retrieves the block at the given height from the archiver.
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
std::pair< ip_address, port_number_t > endpoint_t
[host name, port number].
Definition socket.hpp:19
auto from_buffer(nuraft::buffer &buf) -> std::optional< T >
Deserialize object of given type from a nuraft::buffer.