diff --git a/nano/lib/constants.hpp b/nano/lib/constants.hpp index 9be2902edc..f58438bd15 100644 --- a/nano/lib/constants.hpp +++ b/nano/lib/constants.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace nano { @@ -235,11 +236,22 @@ class network_constants return error; } - char const * get_current_network_as_string () + std::string_view get_current_network_as_string () const { - return is_live_network () ? "live" : is_beta_network () ? "beta" - : is_test_network () ? "test" - : "dev"; + switch (current_network) + { + case nano::networks::nano_live_network: + return "live"; + case nano::networks::nano_beta_network: + return "beta"; + case nano::networks::nano_dev_network: + return "dev"; + case nano::networks::nano_test_network: + return "test"; + case networks::invalid: + break; + } + release_assert (false, "invalid network"); } bool is_live_network () const diff --git a/nano/load_test/entry.cpp b/nano/load_test/entry.cpp index aaf62fc0a8..cf7362c9d2 100644 --- a/nano/load_test/entry.cpp +++ b/nano/load_test/entry.cpp @@ -580,7 +580,7 @@ int main (int argc, char * const * argv) data_paths.push_back (std::move (data_path)); } - auto current_network = nano::dev::network_params.network.get_current_network_as_string (); + std::string current_network{ nano::dev::network_params.network.get_current_network_as_string () }; std::vector> nodes; std::vector> rpc_servers; for (auto const & data_path : data_paths) diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 2922b729de..8275752432 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -170,8 +170,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag throw std::runtime_error (std::string ("RPC is configured to spawn a new process however the file cannot be found at: ") + config.rpc.child_process.rpc_path); } - auto network = node->network_params.network.get_current_network_as_string (); - + std::string network{ node->network_params.network.get_current_network_as_string () }; rpc_process = std::make_unique (config.rpc.child_process.rpc_path, "--daemon", "--data_path", data_path.string (), "--network", network); } debug_assert (rpc || rpc_process); diff --git a/nano/nano_wallet/entry.cpp b/nano/nano_wallet/entry.cpp index 0efa061a93..195ac64f8d 100644 --- a/nano/nano_wallet/entry.cpp +++ b/nano/nano_wallet/entry.cpp @@ -192,7 +192,7 @@ class wallet_daemon final throw std::runtime_error (std::string ("RPC is configured to spawn a new process however the file cannot be found at: ") + config.rpc.child_process.rpc_path); } - auto network = node->network_params.network.get_current_network_as_string (); + std::string network{ node->network_params.network.get_current_network_as_string () }; rpc_process = std::make_unique (config.rpc.child_process.rpc_path, "--daemon", "--data_path", data_path.string (), "--network", network); } } diff --git a/nano/node/portmapping.cpp b/nano/node/portmapping.cpp index 0dd1605bda..6e5db0329b 100644 --- a/nano/node/portmapping.cpp +++ b/nano/node/portmapping.cpp @@ -7,6 +7,8 @@ #include +#include + std::string nano::mapping_protocol::to_string () { std::stringstream ss; @@ -179,7 +181,7 @@ void nano::port_mapping::refresh_mapping () // We don't map the RPC port because, unless RPC authentication was added, this would almost always be a security risk for (auto & protocol : protocols | boost::adaptors::filtered ([] (auto const & p) { return p.enabled; })) { - auto upnp_description = std::string ("Nano Node (") + node.network_params.network.get_current_network_as_string () + ")"; + auto upnp_description = fmt::format ("Nano Node ({})", node.network_params.network.get_current_network_as_string ()); std::string address_str = address.to_string (); std::string lease_duration_str = std::to_string (node.network_params.portmapping.lease_duration.count ()); diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index db6365077c..b2a17b3d92 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -14,6 +14,8 @@ #include #include +#include + namespace { void show_line_error (QLineEdit & line) @@ -75,12 +77,14 @@ nano_qt::self_pane::self_pane (nano_qt::wallet & wallet_a, nano::account const & wallet (wallet_a) { your_account_label->setStyleSheet ("font-weight: bold;"); - std::string network = wallet.node.network_params.network.get_current_network_as_string (); + + // Capitalize the first letter + std::string network{ wallet.node.network_params.network.get_current_network_as_string () }; if (!network.empty ()) { network[0] = std::toupper (network[0]); } - version = new QLabel (boost::str (boost::format ("%1% %2% network") % NANO_VERSION_STRING % network).c_str ()); + version = new QLabel (fmt::format ("{} {} network", NANO_VERSION_STRING, network).c_str ()); self_layout->addWidget (your_account_label); self_layout->addStretch ();