Code formatting
This commit is contained in:
parent
6e2fb6fac5
commit
5860002d0a
3 changed files with 104 additions and 126 deletions
|
|
@ -3,3 +3,4 @@
|
|||
find ./libraries/app -regex ".*[c|h]pp" | xargs clang-format -i
|
||||
find ./libraries/chain/hardfork.d -regex ".*hf" | xargs clang-format -i
|
||||
find ./libraries/plugins/peerplays_sidechain -regex ".*[c|h]pp" | xargs clang-format -i
|
||||
find ./programs/cli_wallet -regex ".*[c|h]pp" | xargs clang-format -i
|
||||
|
|
|
|||
|
|
@ -27,8 +27,18 @@
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include <fc/interprocess/signals.hpp>
|
||||
#include <fc/io/json.hpp>
|
||||
#include <fc/io/stdio.hpp>
|
||||
#include <fc/log/console_appender.hpp>
|
||||
#include <fc/log/file_appender.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/log/logger_config.hpp>
|
||||
#include <fc/network/http/server.hpp>
|
||||
#include <fc/network/http/websocket.hpp>
|
||||
#include <fc/rpc/cli.hpp>
|
||||
|
|
@ -40,22 +50,10 @@
|
|||
#include <graphene/chain/config.hpp>
|
||||
#include <graphene/chain/protocol/protocol.hpp>
|
||||
#include <graphene/egenesis/egenesis.hpp>
|
||||
#include <graphene/utilities/git_revision.hpp>
|
||||
#include <graphene/utilities/key_conversion.hpp>
|
||||
#include <graphene/wallet/wallet.hpp>
|
||||
|
||||
#include <fc/interprocess/signals.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <fc/log/console_appender.hpp>
|
||||
#include <fc/log/file_appender.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/log/logger_config.hpp>
|
||||
|
||||
#include <graphene/utilities/git_revision.hpp>
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <signal.h>
|
||||
#else
|
||||
|
|
@ -69,24 +67,22 @@ using namespace graphene::wallet;
|
|||
using namespace std;
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
|
||||
boost::program_options::options_description opts;
|
||||
opts.add_options()
|
||||
("help,h", "Print this help message and exit.")
|
||||
("version,v", "Display the version info and exit")
|
||||
("server-rpc-endpoint,s", bpo::value<string>()->implicit_value("ws://127.0.0.1:8090"), "Server websocket RPC endpoint")
|
||||
("server-rpc-user,u", bpo::value<string>(), "Server Username")
|
||||
("server-rpc-password,p", bpo::value<string>(), "Server Password")
|
||||
("rpc-endpoint,r", bpo::value<string>()->implicit_value("127.0.0.1:8091"), "Endpoint for wallet websocket RPC to listen on")
|
||||
("rpc-tls-endpoint,t", bpo::value<string>()->implicit_value("127.0.0.1:8092"), "Endpoint for wallet websocket TLS RPC to listen on")
|
||||
("rpc-tls-certificate,c", bpo::value<string>()->implicit_value("server.pem"), "PEM certificate for wallet websocket TLS RPC")
|
||||
("rpc-http-endpoint,H", bpo::value<string>()->implicit_value("127.0.0.1:8093"), "Endpoint for wallet HTTP RPC to listen on")
|
||||
("daemon,d", "Run the wallet in daemon mode" )
|
||||
("wallet-file,w", bpo::value<string>()->implicit_value("wallet.json"), "wallet to load")
|
||||
("chain-id", bpo::value<string>(), "chain ID to connect to");
|
||||
opts.add_options()("help,h", "Print this help message and exit.");
|
||||
opts.add_options()("version,v", "Display the version info and exit");
|
||||
opts.add_options()("server-rpc-endpoint,s", bpo::value<string>()->implicit_value("ws://127.0.0.1:8090"), "Server websocket RPC endpoint");
|
||||
opts.add_options()("server-rpc-user,u", bpo::value<string>(), "Server Username");
|
||||
opts.add_options()("server-rpc-password,p", bpo::value<string>(), "Server Password");
|
||||
opts.add_options()("rpc-endpoint,r", bpo::value<string>()->implicit_value("127.0.0.1:8091"), "Endpoint for wallet websocket RPC to listen on");
|
||||
opts.add_options()("rpc-tls-endpoint,t", bpo::value<string>()->implicit_value("127.0.0.1:8092"), "Endpoint for wallet websocket TLS RPC to listen on");
|
||||
opts.add_options()("rpc-tls-certificate,c", bpo::value<string>()->implicit_value("server.pem"), "PEM certificate for wallet websocket TLS RPC");
|
||||
opts.add_options()("rpc-http-endpoint,H", bpo::value<string>()->implicit_value("127.0.0.1:8093"), "Endpoint for wallet HTTP RPC to listen on");
|
||||
opts.add_options()("daemon,d", "Run the wallet in daemon mode");
|
||||
opts.add_options()("wallet-file,w", bpo::value<string>()->implicit_value("wallet.json"), "wallet to load");
|
||||
opts.add_options()("chain-id", bpo::value<string>(), "chain ID to connect to");
|
||||
|
||||
bpo::variables_map options;
|
||||
|
||||
|
|
@ -101,14 +97,12 @@ int main( int argc, char** argv )
|
|||
}
|
||||
bpo::store(po, options);
|
||||
|
||||
if( options.count("help") )
|
||||
{
|
||||
if (options.count("help")) {
|
||||
std::cout << opts << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (options.count("version"))
|
||||
{
|
||||
if (options.count("version")) {
|
||||
std::string wallet_version(graphene::utilities::git_revision_description);
|
||||
const size_t pos = wallet_version.find('/');
|
||||
if (pos != std::string::npos && wallet_version.size() > pos)
|
||||
|
|
@ -163,28 +157,20 @@ int main( int argc, char** argv )
|
|||
wallet_data wdata;
|
||||
|
||||
fc::path wallet_file(options.count("wallet-file") ? options.at("wallet-file").as<string>() : "wallet.json");
|
||||
if( fc::exists( wallet_file ) )
|
||||
{
|
||||
if (fc::exists(wallet_file)) {
|
||||
wdata = fc::json::from_file(wallet_file).as<wallet_data>(GRAPHENE_MAX_NESTED_OBJECTS);
|
||||
if( options.count("chain-id") )
|
||||
{
|
||||
if (options.count("chain-id")) {
|
||||
// the --chain-id on the CLI must match the chain ID embedded in the wallet file
|
||||
if( chain_id_type(options.at("chain-id").as<std::string>()) != wdata.chain_id )
|
||||
{
|
||||
if (chain_id_type(options.at("chain-id").as<std::string>()) != wdata.chain_id) {
|
||||
std::cout << "Chain ID in wallet file does not match specified chain ID\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( options.count("chain-id") )
|
||||
{
|
||||
} else {
|
||||
if (options.count("chain-id")) {
|
||||
wdata.chain_id = chain_id_type(options.at("chain-id").as<std::string>());
|
||||
std::cout << "Starting a new wallet with chain ID " << wdata.chain_id.str() << " (from CLI)\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
wdata.chain_id = graphene::egenesis::get_egenesis_chain_id();
|
||||
std::cout << "Starting a new wallet with chain ID " << wdata.chain_id.str() << " (from egenesis)\n";
|
||||
}
|
||||
|
|
@ -223,8 +209,7 @@ int main( int argc, char** argv )
|
|||
}));
|
||||
(void)(closed_connection);
|
||||
|
||||
if( wapiptr->is_new() )
|
||||
{
|
||||
if (wapiptr->is_new()) {
|
||||
std::cout << "Please use the set_password method to initialize a new wallet before continuing\n";
|
||||
wallet_cli->set_prompt("new >>> ");
|
||||
} else
|
||||
|
|
@ -235,8 +220,7 @@ int main( int argc, char** argv )
|
|||
}));
|
||||
|
||||
std::shared_ptr<fc::http::websocket_server> _websocket_server;
|
||||
if( options.count("rpc-endpoint") )
|
||||
{
|
||||
if (options.count("rpc-endpoint")) {
|
||||
_websocket_server = std::make_shared<fc::http::websocket_server>();
|
||||
_websocket_server->on_connection([&wapi](const fc::http::websocket_connection_ptr &c) {
|
||||
std::cout << "here... \n";
|
||||
|
|
@ -255,8 +239,7 @@ int main( int argc, char** argv )
|
|||
cert_pem = options.at("rpc-tls-certificate").as<string>();
|
||||
|
||||
std::shared_ptr<fc::http::websocket_tls_server> _websocket_tls_server;
|
||||
if( options.count("rpc-tls-endpoint") )
|
||||
{
|
||||
if (options.count("rpc-tls-endpoint")) {
|
||||
_websocket_tls_server = std::make_shared<fc::http::websocket_tls_server>(cert_pem);
|
||||
_websocket_tls_server->on_connection([&](const fc::http::websocket_connection_ptr &c) {
|
||||
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_MAX_NESTED_OBJECTS);
|
||||
|
|
@ -269,16 +252,14 @@ int main( int argc, char** argv )
|
|||
}
|
||||
|
||||
auto _http_server = std::make_shared<fc::http::server>();
|
||||
if( options.count("rpc-http-endpoint" ) )
|
||||
{
|
||||
if (options.count("rpc-http-endpoint")) {
|
||||
ilog("Listening for incoming HTTP RPC requests on ${p}", ("p", options.at("rpc-http-endpoint").as<string>()));
|
||||
_http_server->listen(fc::ip::endpoint::from_string(options.at("rpc-http-endpoint").as<string>()));
|
||||
//
|
||||
// due to implementation, on_request() must come AFTER listen()
|
||||
//
|
||||
_http_server->on_request(
|
||||
[&wapi]( const fc::http::request& req, const fc::http::server::response& resp )
|
||||
{
|
||||
[&wapi](const fc::http::request &req, const fc::http::server::response &resp) {
|
||||
std::shared_ptr<fc::rpc::http_api_connection> conn =
|
||||
std::make_shared<fc::rpc::http_api_connection>(GRAPHENE_MAX_NESTED_OBJECTS);
|
||||
conn->register_api(wapi);
|
||||
|
|
@ -286,18 +267,16 @@ int main( int argc, char** argv )
|
|||
});
|
||||
}
|
||||
|
||||
if( !options.count( "daemon" ) )
|
||||
{
|
||||
if (!options.count("daemon")) {
|
||||
wallet_cli->register_api(wapi);
|
||||
wallet_cli->start();
|
||||
wallet_cli->wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fc::promise<int>::ptr exit_promise = new fc::promise<int>("UNIX Signal Handler");
|
||||
fc::set_signal_handler([&exit_promise](int signal) {
|
||||
exit_promise->set_value(signal);
|
||||
}, SIGINT);
|
||||
},
|
||||
SIGINT);
|
||||
|
||||
ilog("Entering Daemon Mode, ^C to exit");
|
||||
exit_promise->wait();
|
||||
|
|
@ -306,9 +285,7 @@ int main( int argc, char** argv )
|
|||
wapi->save_wallet_file(wallet_file.generic_string());
|
||||
locked_connection.disconnect();
|
||||
closed_connection.disconnect();
|
||||
}
|
||||
catch ( const fc::exception& e )
|
||||
{
|
||||
} catch (const fc::exception &e) {
|
||||
std::cout << e.to_detail_string() << "\n";
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue