OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
ticket_machined.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 "controller.hpp"
7#include "util.hpp"
9#include "util/rpc/format.hpp"
12
13#include <csignal>
14
15auto main(int argc, char** argv) -> int {
16 auto log
17 = std::make_shared<cbdc::logging::log>(cbdc::logging::log_level::warn);
18 auto cfg = cbdc::parsec::read_config(argc, argv);
19 if(!cfg.has_value()) {
20 log->error("Error parsing options");
21 return 1;
22 }
23 log->set_loglevel(cfg->m_loglevel);
24 if(cfg->m_component_id >= cfg->m_ticket_machine_endpoints.size()) {
25 log->error("No endpoint specified for ticket machine");
26 return 1;
27 }
28
29 auto raft_endpoints = std::vector<cbdc::network::endpoint_t>();
30 for(auto& e : cfg->m_ticket_machine_endpoints) {
31 auto new_ep = e;
32 new_ep.second++;
33 raft_endpoints.push_back(new_ep);
34 }
35
37 cfg->m_component_id,
38 cfg->m_ticket_machine_endpoints[cfg->m_component_id],
39 raft_endpoints,
40 log);
41 if(!raft_server.init()) {
42 log->error("Failed to start raft server");
43 return 1;
44 }
45
46 static auto running = std::atomic_bool{true};
47
48 std::signal(SIGINT, [](int /* signal */) {
49 running = false;
50 });
51
52 log->info("Ticket machine running");
53
54 while(running) {
55 std::this_thread::sleep_for(std::chrono::seconds(1));
56 }
57
58 log->info("Shutting down...");
59
60 return 0;
61}
Manages a replicated ticket machine using Raft.
@ warn
Potentially unintended, unexpected, or undesirable behavior.
auto read_config(int argc, char **argv) -> std::optional< config >
Reads the configuration parameters from the program arguments.
Definition util.cpp:100
auto main(int argc, char **argv) -> int