Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 30, 2024
1 parent 9311e4d commit 5a01082
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
20 changes: 16 additions & 4 deletions nano/lib/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nano/lib/fwd.hpp>

#include <chrono>
#include <string_view>

namespace nano
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nano/load_test/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<boost::process::child>> nodes;
std::vector<std::unique_ptr<boost::process::child>> rpc_servers;
for (auto const & data_path : data_paths)
Expand Down
3 changes: 1 addition & 2 deletions nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<boost::process::child> (config.rpc.child_process.rpc_path, "--daemon", "--data_path", data_path.string (), "--network", network);
}
debug_assert (rpc || rpc_process);
Expand Down
2 changes: 1 addition & 1 deletion nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<boost::process::child> (config.rpc.child_process.rpc_path, "--daemon", "--data_path", data_path.string (), "--network", network);
}
}
Expand Down
4 changes: 3 additions & 1 deletion nano/node/portmapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <boost/range/adaptor/filtered.hpp>

#include <fmt/format.h>

std::string nano::mapping_protocol::to_string ()
{
std::stringstream ss;
Expand Down Expand Up @@ -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 ());

Expand Down
8 changes: 6 additions & 2 deletions nano/qt/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <iomanip>
#include <sstream>

#include <fmt/format.h>

namespace
{
void show_line_error (QLineEdit & line)
Expand Down Expand Up @@ -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 ();
Expand Down

0 comments on commit 5a01082

Please sign in to comment.