diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index b837b6e045..5b5b5bbdfd 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -77,10 +76,12 @@ int main( int argc, char** argv ) ("server-rpc-endpoint,s", bpo::value()->implicit_value("ws://127.0.0.1:8090"), "Server websocket RPC endpoint") ("server-rpc-user,u", bpo::value(), "Server Username") ("server-rpc-password,p", bpo::value(), "Server Password") - ("rpc-endpoint,r", bpo::value()->implicit_value("127.0.0.1:8091"), "Endpoint for wallet websocket RPC to listen on") + ("rpc-endpoint,r", bpo::value()->implicit_value("127.0.0.1:8091"), + "Endpoint for wallet websocket RPC to listen on (DEPRECATED, use rpc-http-endpoint instead)") ("rpc-tls-endpoint,t", bpo::value()->implicit_value("127.0.0.1:8092"), "Endpoint for wallet websocket TLS RPC to listen on") ("rpc-tls-certificate,c", bpo::value()->implicit_value("server.pem"), "PEM certificate for wallet websocket TLS RPC") - ("rpc-http-endpoint,H", bpo::value()->implicit_value("127.0.0.1:8093"), "Endpoint for wallet HTTP RPC to listen on") + ("rpc-http-endpoint,H", bpo::value()->implicit_value("127.0.0.1:8093"), + "Endpoint for wallet HTTP and websocket RPC to listen on") ("daemon,d", "Run the wallet in daemon mode" ) ("wallet-file,w", bpo::value()->implicit_value("wallet.json"), "wallet to load") ("chain-id", bpo::value(), "chain ID to connect to") @@ -205,15 +206,16 @@ int main( int argc, char** argv ) fc::api wapi(wapiptr); - auto _websocket_server = std::make_shared(); + std::shared_ptr _websocket_server; if( options.count("rpc-endpoint") ) { + _websocket_server = std::make_shared(); _websocket_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); c->set_session_data( wsc ); }); - ilog( "Listening for incoming RPC requests on ${p}", ("p", options.at("rpc-endpoint").as() )); + ilog( "Listening for incoming HTTP and WS RPC requests on ${p}", ("p", options.at("rpc-endpoint").as() )); _websocket_server->listen( fc::ip::endpoint::from_string(options.at("rpc-endpoint").as()) ); _websocket_server->start_accept(); } @@ -222,37 +224,34 @@ int main( int argc, char** argv ) if( options.count( "rpc-tls-certificate" ) ) cert_pem = options.at("rpc-tls-certificate").as(); - auto _websocket_tls_server = std::make_shared(cert_pem); + std::shared_ptr _websocket_tls_server; if( options.count("rpc-tls-endpoint") ) { + _websocket_tls_server = std::make_shared(cert_pem); _websocket_tls_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); c->set_session_data( wsc ); }); - ilog( "Listening for incoming TLS RPC requests on ${p}", + ilog( "Listening for incoming HTTPS and WSS RPC requests on ${p}", ("p", options.at("rpc-tls-endpoint").as()) ); _websocket_tls_server->listen( fc::ip::endpoint::from_string(options.at("rpc-tls-endpoint").as()) ); _websocket_tls_server->start_accept(); } - auto _http_server = std::make_shared(); + std::shared_ptr _http_ws_server; if( options.count("rpc-http-endpoint" ) ) { - ilog( "Listening for incoming HTTP RPC requests on ${p}", + _http_ws_server = std::make_shared(); + ilog( "Listening for incoming HTTP and WS RPC requests on ${p}", ("p", options.at("rpc-http-endpoint").as()) ); - _http_server->listen( fc::ip::endpoint::from_string( options.at( "rpc-http-endpoint" ).as() ) ); - // - // 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 ) - { - 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 ); - conn->on_request( req, resp ); - } ); + _http_ws_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ + auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); + wsc->register_api(wapi); + c->set_session_data( wsc ); + }); + _http_ws_server->listen( fc::ip::endpoint::from_string(options.at("rpc-http-endpoint").as()) ); + _http_ws_server->start_accept(); } if( !options.count( "daemon" ) )