OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
watchtowerd.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 "crypto/sha256.h"
11
12#include <csignal>
13
14// LCOV_EXCL_START
15auto main(int argc, char** argv) -> int {
16 auto args = cbdc::config::get_args(argc, argv);
17 if(args.size() < 3) {
18 std::cerr << "Usage: " << args[0] << " <config file> <watchtower ID>"
19 << std::endl;
20 return 0;
21 }
22
23 const auto watchtower_id = std::stoull(args[2]);
24
25 auto cfg_or_err = cbdc::config::load_options(args[1]);
26 if(std::holds_alternative<std::string>(cfg_or_err)) {
27 std::cerr << "Error loading config file: "
28 << std::get<std::string>(cfg_or_err) << std::endl;
29 return -1;
30 }
31 auto opts = std::get<cbdc::config::options>(cfg_or_err);
32
33 auto logger = std::make_shared<cbdc::logging::log>(
34 opts.m_watchtower_loglevels[watchtower_id]);
35
36 auto ctl
37 = cbdc::watchtower::controller{static_cast<uint32_t>(watchtower_id),
38 opts,
39 logger};
40
41 if(!ctl.init()) {
42 return -1;
43 }
44
45 static std::atomic_bool running{true};
46
47 std::signal(SIGINT, [](int /* signal */) {
48 running = false;
49 });
50
51 while(running) {
52 std::this_thread::sleep_for(std::chrono::seconds(1));
53 };
54
55 logger->info("Shutting down...");
56
57 return 0;
58}
59// LCOV_EXCL_STOP
Wrapper for the watchtower executable implementation.
Tools for reading options from a configuration file and building application-specific parameter sets ...
auto load_options(const std::string &config_file) -> std::variant< options, std::string >
Loads options from the given config file and check for invariants.
Definition config.cpp:668
auto get_args(int argc, char **argv) -> std::vector< std::string >
Converts c-args from an executable's main function into a vector of strings.
Definition config.cpp:751
auto main(int argc, char **argv) -> int