OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
uhs/sentinel/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
11
12namespace cbdc::sentinel::rpc {
13 client::client(std::vector<network::endpoint_t> endpoints,
14 std::shared_ptr<logging::log> logger)
15 : m_logger(std::move(logger)),
16 m_client(std::move(endpoints)) {}
17
18 auto client::init(std::optional<bool> error_fatal) -> bool {
19 if(!m_client.init(error_fatal)) {
20 m_logger->error("Failed to initialize sentinel RPC client");
21 return false;
22 }
23 return true;
24 }
25
27 -> std::optional<execute_response> {
28 auto res = m_client.call(execute_request{std::move(tx)});
29 if(!res.has_value()) {
30 return std::nullopt;
31 }
32 return std::get<execute_response>(res.value());
33 }
34
37 std::function<void(execute_result_type)> result_callback) -> bool {
38 return m_client.call(
39 execute_request{std::move(tx)},
40 [cb = std::move(result_callback)](std::optional<response> res) {
41 if(!res.has_value()) {
42 cb(std::nullopt);
43 return;
44 }
45 cb(std::get<execute_response>(res.value()));
46 });
47 }
48
50 -> std::optional<validate_response> {
51 auto res = m_client.call(validate_request{std::move(tx)});
52 if(!res.has_value()) {
53 return std::nullopt;
54 }
55 return std::get<validate_response>(res.value());
56 }
57
60 std::function<void(validate_result_type)> result_callback) -> bool {
61 return m_client.call(
62 validate_request{std::move(tx)},
63 [cb = std::move(result_callback)](std::optional<response> res) {
64 if(!res.has_value()) {
65 cb(std::nullopt);
66 return;
67 }
68 cb(std::get<validate_response>(res.value()));
69 });
70 }
71}
auto init() -> bool
Initializes the client.
std::optional< validate_response > validate_result_type
Return type from transaction validation.
auto validate_transaction(transaction::full_tx tx) -> validate_result_type override
Send a transaction to the sentinel for validation and return the response.
std::optional< cbdc::sentinel::execute_response > execute_result_type
Result type from execute_transaction.
auto execute_transaction(transaction::full_tx tx) -> execute_result_type override
Send a transaction to the sentinel and return the response.
Request type for transaction validation and attestation.
A complete transaction.