13 const std::shared_ptr<logging::log>& logger,
14 const std::string& wallet_file,
15 const std::string& client_file)
16 :
client(opts, logger, wallet_file, client_file),
17 m_coordinator_client(opts.m_coordinator_endpoints[0]),
18 m_shard_status_client(opts.m_locking_shard_readonly_endpoints,
25 if(!m_coordinator_client.init()) {
26 m_logger->warn(
"Failed to initialize coordinator client");
29 if(!m_shard_status_client.init()) {
30 m_logger->warn(
"Failed to initialize shard status client");
39 auto txids = std::set<hash_t>();
40 for(
const auto& [tx_id, tx] : pending_txs()) {
43 for(
const auto& [tx_id, inp] : pending_inputs()) {
47 for(
const auto& tx_id : txids) {
48 m_logger->debug(
"Requesting status of",
to_string(tx_id));
49 auto res = m_shard_status_client.check_tx_id(tx_id);
50 if(!res.has_value()) {
51 m_logger->error(
"Timeout waiting for shard response");
55 m_logger->info(
to_string(tx_id),
"confirmed");
56 confirm_transaction(tx_id);
58 m_logger->info(
to_string(tx_id),
"not found");
67 -> std::optional<bool> {
68 return m_shard_status_client.check_tx_id(tx_id);
72 -> std::optional<bool> {
73 return m_shard_status_client.check_unspent(uhs_id);
79 for(
size_t i = 0; i < m_opts.m_attestation_threshold; i++) {
81 = ctx.sign(m_secp.get(), m_opts.m_sentinel_private_keys[i]);
82 ctx.m_attestations.insert(att);
84 auto done = std::promise<void>();
85 auto done_fut = done.get_future();
86 auto res = m_coordinator_client.execute_transaction(
88 [&, tx_id = ctx.m_id](std::optional<bool> success) {
89 if(!success.has_value()) {
91 "Coordinator error processing transaction");
94 if(!success.value()) {
95 m_logger->error(
"Coordinator rejected transaction");
98 confirm_transaction(tx_id);
99 m_logger->info(
"Confirmed mint TX");
103 m_logger->error(
"Failed to send transaction to coordinator");
106 constexpr auto timeout = std::chrono::seconds(5);
107 auto maybe_timeout = done_fut.wait_for(timeout);
108 if(maybe_timeout == std::future_status::timeout) {
109 m_logger->error(
"Timed out waiting for mint response");
External client for sending new transactions to the system.
auto check_unspent(const hash_t &uhs_id) -> std::optional< bool >
Checks the shard network for the status of a specific UHS ID.
auto sync() -> bool override
Update the client with the latest state from the shard network.
auto send_mint_tx(const transaction::full_tx &mint_tx) -> bool override
Sends the given mint transaction directly to a coordinator cluster.
auto check_tx_id(const hash_t &tx_id) -> std::optional< bool >
Checks the shard network for the status of a specific transaction.
auto init_derived() -> bool override
Initializes the 2PC architecture client.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
auto to_string(const hash_t &val) -> std::string
Converts a hash to a hexadecimal string.
Project-wide configuration options.
A condensed, hash-only transaction representation.