@@ -166,7 +166,8 @@ bfs::path determine_home_directory()
166
166
}
167
167
168
168
string url = " http://127.0.0.1:8888/" ;
169
- string wallet_url = " http://127.0.0.1:8900/" ;
169
+ string default_wallet_url = " unix://" + (determine_home_directory() / " eosio-wallet" / (string(key_store_executable_name) + " .sock" )).string();
170
+ string wallet_url; // to be set to default_wallet_url in main
170
171
bool no_verify = false ;
171
172
vector<string> headers;
172
173
@@ -768,25 +769,22 @@ struct set_action_permission_subcommand {
768
769
};
769
770
770
771
771
- bool local_port_used (const string& lo_address, uint16_t port ) {
772
+ bool local_port_used () {
772
773
using namespace boost ::asio;
773
774
774
775
io_service ios;
775
- boost::asio::ip::tcp::endpoint endpoint (boost::asio::ip::address::from_string (lo_address), port);
776
- boost::asio::ip::tcp::socket socket (ios);
777
- boost::system::error_code ec = error::would_block;
778
- // connecting/failing to connect to localhost should be always fast - don't care about timeouts
779
- socket.async_connect (endpoint, [&](const boost::system::error_code& error) { ec = error; } );
780
- do {
781
- ios.run_one ();
782
- } while (ec == error::would_block);
776
+ local::stream_protocol::endpoint endpoint (wallet_url.substr (strlen (" unix://" )));
777
+ local::stream_protocol::socket socket (ios);
778
+ boost::system::error_code ec;
779
+ socket.connect (endpoint, ec);
780
+
783
781
return !ec;
784
782
}
785
783
786
- void try_local_port ( const string& lo_address, uint16_t port, uint32_t duration ) {
784
+ void try_local_port (uint32_t duration) {
787
785
using namespace std ::chrono;
788
786
auto start_time = duration_cast<std::chrono::milliseconds>( system_clock::now ().time_since_epoch () ).count ();
789
- while ( !local_port_used (lo_address, port )) {
787
+ while ( !local_port_used ()) {
790
788
if (duration_cast<std::chrono::milliseconds>( system_clock::now ().time_since_epoch ()).count () - start_time > duration ) {
791
789
std::cerr << " Unable to connect to keosd, if keosd is running please kill the process and try again.\n " ;
792
790
throw connection_exception (fc::log_messages{FC_LOG_MESSAGE (error, " Unable to connect to keosd" )});
@@ -806,16 +804,11 @@ void ensure_keosd_running(CLI::App* app) {
806
804
if (subapp->got_subcommand (" listproducers" ) || subapp->got_subcommand (" listbw" ) || subapp->got_subcommand (" bidnameinfo" )) // system list* do not require wallet
807
805
return ;
808
806
}
807
+ if (wallet_url != default_wallet_url)
808
+ return ;
809
809
810
- auto parsed_url = parse_url (wallet_url);
811
- auto resolved_url = resolve_url (context, parsed_url);
812
-
813
- if (!resolved_url.is_loopback )
814
- return ;
815
-
816
- for (const auto & addr: resolved_url.resolved_addresses )
817
- if (local_port_used (addr, resolved_url.resolved_port )) // Hopefully taken by keosd
818
- return ;
810
+ if (local_port_used ())
811
+ return ;
819
812
820
813
boost::filesystem::path binPath = boost::dll::program_location ();
821
814
binPath.remove_filename ();
@@ -827,13 +820,15 @@ void ensure_keosd_running(CLI::App* app) {
827
820
binPath.remove_filename ().remove_filename ().append (" keosd" ).append (key_store_executable_name);
828
821
}
829
822
830
- const auto & lo_address = resolved_url.resolved_addresses .front ();
831
823
if (boost::filesystem::exists (binPath)) {
832
824
namespace bp = boost::process;
833
825
binPath = boost::filesystem::canonical (binPath);
834
826
835
827
vector<std::string> pargs;
836
- pargs.push_back (" --http-server-address=" + lo_address + " :" + std::to_string (resolved_url.resolved_port ));
828
+ pargs.push_back (" --http-server-address" );
829
+ pargs.push_back (" " );
830
+ pargs.push_back (" --https-server-address" );
831
+ pargs.push_back (" " );
837
832
838
833
::boost::process::child keos (binPath, pargs,
839
834
bp::std_in.close (),
@@ -842,13 +837,12 @@ void ensure_keosd_running(CLI::App* app) {
842
837
if (keos.running ()) {
843
838
std::cerr << binPath << " launched" << std::endl;
844
839
keos.detach ();
845
- try_local_port (lo_address, resolved_url. resolved_port , 2000 );
840
+ try_local_port (2000 );
846
841
} else {
847
- std::cerr << " No wallet service listening on " << lo_address << " :"
848
- << std::to_string (resolved_url.resolved_port ) << " . Failed to launch " << binPath << std::endl;
842
+ std::cerr << " No wallet service listening on " << wallet_url << " . Failed to launch " << binPath << std::endl;
849
843
}
850
844
} else {
851
- std::cerr << " No wallet service listening on " << lo_address << " : " << std::to_string (resolved_url. resolved_port )
845
+ std::cerr << " No wallet service listening on "
852
846
<< " . Cannot automatically start keosd because keosd was not found." << std::endl;
853
847
}
854
848
}
@@ -1745,6 +1739,7 @@ int main( int argc, char** argv ) {
1745
1739
bindtextdomain (locale_domain, locale_path);
1746
1740
textdomain (locale_domain);
1747
1741
context = eosio::client::http::create_http_context ();
1742
+ wallet_url = default_wallet_url;
1748
1743
1749
1744
CLI::App app{" Command Line Interface to EOSIO Client" };
1750
1745
app.require_subcommand ();
0 commit comments