Loading...
Searching...
No Matches
utxo_service.cpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#include <glog/logging.h>
21#include <google/protobuf/util/json_util.h>
22
23#include <fstream>
24
29
30using google::protobuf::util::JsonParseOptions;
34using resdb::ResConfigData;
36using resdb::Stats;
41
42resdb::utxo::Config ReadConfigFromFile(const std::string& file_name) {
43 std::stringstream json_data;
44 std::ifstream infile(file_name.c_str());
45 json_data << infile.rdbuf();
46
47 resdb::utxo::Config config_data;
48 JsonParseOptions options;
49 auto status = JsonStringToMessage(json_data.str(), &config_data, options);
50 if (!status.ok()) {
51 LOG(ERROR) << "parse json :" << file_name << " fail:" << status.message();
52 }
53 assert(status.ok());
54 return config_data;
55}
56
57void ShowUsage() {
58 printf(
59 "<config> <private_key> <cert_file> <durability_option> [logging_dir]\n");
60}
61
62int main(int argc, char** argv) {
63 if (argc < 4) {
64 ShowUsage();
65 exit(0);
66 }
67
68 char* config_file = argv[1];
69 char* private_key_file = argv[2];
70 char* cert_file = argv[3];
71
72 char* utxo_config_file = argv[4];
73
74 if (argc >= 6) {
75 auto monitor_port = Stats::GetGlobalStats(5);
76 monitor_port->SetPrometheus(argv[5]);
77 }
78
79 resdb::utxo::Config utxo_config = ReadConfigFromFile(utxo_config_file);
80
81 std::unique_ptr<ResDBConfig> config =
82 GenerateResDBConfig(config_file, private_key_file, cert_file);
83 ResConfigData config_data = config->GetConfigData();
84
85 std::unique_ptr<Wallet> wallet = std::make_unique<Wallet>();
86 std::unique_ptr<Transaction> transaction =
87 std::make_unique<Transaction>(utxo_config, wallet.get());
88
89 auto server = CustomGenerateResDBServer<ConsensusManagerPBFT>(
90 config_file, private_key_file, cert_file,
91 std::make_unique<UTXOExecutor>(utxo_config, transaction.get(),
92 wallet.get()),
93 std::make_unique<QueryExecutor>(transaction.get(), wallet.get()));
94
95 server->Run();
96}
static Stats * GetGlobalStats(int sleep_seconds=5)
Definition stats.cpp:29
std::unique_ptr< ServiceNetwork > CustomGenerateResDBServer(char *config_file, char *private_key_file, char *cert_file, std::unique_ptr< TransactionManager > executor, char *logging_dir=nullptr, std::function< void(ResDBConfig *config)> config_handler=nullptr)
std::unique_ptr< ResDBConfig > GenerateResDBConfig(const std::string &config_file, const std::string &private_key_file, const std::string &cert_file, std::optional< ReplicaInfo > self_info, std::optional< ConfigGenFunc > gen_func)
int main(int argc, char **argv)
void ShowUsage()
resdb::utxo::Config ReadConfigFromFile(const std::string &file_name)