OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
status_client.hpp
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#ifndef TX_STATUS_CLIENT_H_INC
7#define TX_STATUS_CLIENT_H_INC
8
10#include "status_messages.hpp"
13
20 public:
29 status_client(std::vector<std::vector<network::endpoint_t>>
30 shard_read_only_endpoints,
31 std::vector<config::shard_range_t> shard_ranges,
32 std::chrono::milliseconds timeout
33 = std::chrono::milliseconds::zero());
34
36 ~status_client() override = default;
37
38 status_client() = delete;
39 status_client(const status_client&) = delete;
40 auto operator=(const status_client&) -> status_client& = delete;
43
47 auto init() -> bool;
48
54 [[nodiscard]] auto check_unspent(const hash_t& uhs_id)
55 -> std::optional<bool> override;
56
62 [[nodiscard]] auto check_tx_id(const hash_t& tx_id)
63 -> std::optional<bool> override;
64
65 private:
66 std::vector<std::unique_ptr<
68 m_shard_clients;
69 std::vector<config::shard_range_t> m_shard_ranges;
70 std::chrono::milliseconds m_request_timeout;
71
72 template<typename T>
73 auto make_request(const hash_t& val) -> std::optional<bool> {
74 // TODO: optimize the algorithm for shard selection.
75 for(size_t i = 0; i < m_shard_ranges.size(); i++) {
76 if(config::hash_in_shard_range(m_shard_ranges[i], val)) {
77 return m_shard_clients[i]->call(T{val}, m_request_timeout);
78 }
79 }
80 return std::nullopt;
81 }
82 };
83}
84
85#endif
Client for interacting with the read-only port on 2PC shards.
auto init() -> bool
Initializes the client by creating a TCP RPC client for each shard cluster.
auto operator=(const status_client &) -> status_client &=delete
status_client(const status_client &)=delete
status_client(status_client &&)=delete
auto operator=(status_client &&) -> status_client &=delete
auto check_tx_id(const hash_t &tx_id) -> std::optional< bool > override
Queries the shard cluster responsible for the given TX ID for whether it is in the confirmed TX IDs c...
~status_client() override=default
Destructor.
auto check_unspent(const hash_t &uhs_id) -> std::optional< bool > override
Queries the shard cluster responsible for the given UHS ID for whether it is unspent.
Interface for querying the read-only state of a locking shard.
Implements an RPC client over TCP sockets.
Tools for reading options from a configuration file and building application-specific parameter sets ...
auto hash_in_shard_range(const shard_range_t &range, const hash_t &val) -> bool
Checks if a hash is in the given range handled.
Definition config.cpp:736
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.