diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 9dd69a31aa..603d4450d9 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -105,11 +105,11 @@ void nano::json_handler::process_request (bool unsafe_a) { mnano_to_raw (nano::kxrb_ratio); } - else if (action == "nano_from_raw" || action == "rai_from_raw") + else if (action == "rai_from_raw") { mnano_from_raw (nano::xrb_ratio); } - else if (action == "nano_to_raw" || action == "rai_to_raw") + else if (action == "rai_to_raw") { mnano_to_raw (nano::xrb_ratio); } @@ -121,6 +121,14 @@ void nano::json_handler::process_request (bool unsafe_a) { mnano_to_raw (); } + else if (action == "nano_to_raw") + { + nano_to_raw (); + } + else if (action == "raw_to_nano") + { + raw_to_nano (); + } else if (action == "password_valid") { password_valid (); @@ -2731,6 +2739,7 @@ void nano::json_handler::ledger () void nano::json_handler::mnano_from_raw (nano::uint128_t ratio) { auto amount (amount_impl ()); + response_l.put ("deprecated", "1"); if (!ec) { auto result (amount.number () / ratio); @@ -2742,6 +2751,7 @@ void nano::json_handler::mnano_from_raw (nano::uint128_t ratio) void nano::json_handler::mnano_to_raw (nano::uint128_t ratio) { auto amount (amount_impl ()); + response_l.put ("deprecated", "1"); if (!ec) { auto result (amount.number () * ratio); @@ -2757,6 +2767,35 @@ void nano::json_handler::mnano_to_raw (nano::uint128_t ratio) response_errors (); } +void nano::json_handler::nano_to_raw () +{ + auto amount (amount_impl ()); + if (!ec) + { + auto result (amount.number () * nano::Mxrb_ratio); + if (result > amount.number ()) + { + response_l.put ("amount", result.convert_to ()); + } + else + { + ec = nano::error_common::invalid_amount_big; + } + } + response_errors (); +} + +void nano::json_handler::raw_to_nano () +{ + auto amount (amount_impl ()); + if (!ec) + { + auto result (amount.number () / nano::Mxrb_ratio); + response_l.put ("amount", result.convert_to ()); + } + response_errors (); +} + /* * @warning This is an internal/diagnostic RPC, do not rely on its interface being stable */ diff --git a/nano/node/json_handler.hpp b/nano/node/json_handler.hpp index 67c6380110..eb743d4b56 100644 --- a/nano/node/json_handler.hpp +++ b/nano/node/json_handler.hpp @@ -75,6 +75,8 @@ class json_handler : public std::enable_shared_from_this void ledger (); void mnano_to_raw (nano::uint128_t = nano::Mxrb_ratio); void mnano_from_raw (nano::uint128_t = nano::Mxrb_ratio); + void nano_to_raw (); + void raw_to_nano (); void node_id (); void node_id_delete (); void password_change (); diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 8001322621..d0a91e87f9 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -1458,16 +1458,8 @@ void nano_qt::wallet::change_rendering_ratio (nano::uint128_t const & rendering_ std::string nano_qt::wallet::format_balance (nano::uint128_t const & balance) const { auto balance_str = nano::amount (balance).format_balance (rendering_ratio, 3, false); - auto unit = std::string ("NANO"); - if (rendering_ratio == nano::kxrb_ratio) - { - unit = std::string ("knano"); - } - else if (rendering_ratio == nano::xrb_ratio) - { - unit = std::string ("nano"); - } - else if (rendering_ratio == nano::raw_ratio) + auto unit = std::string ("nano"); + if (rendering_ratio == nano::raw_ratio) { unit = std::string ("raw"); } @@ -1751,8 +1743,6 @@ nano_qt::advanced_actions::advanced_actions (nano_qt::wallet & wallet_a) : scale_layout (new QHBoxLayout), scale_label (new QLabel ("Scale:")), ratio_group (new QButtonGroup), - mnano_unit (new QRadioButton ("Mnano")), - knano_unit (new QRadioButton ("knano")), nano_unit (new QRadioButton ("nano")), raw_unit (new QRadioButton ("raw")), back (new QPushButton ("Back")), @@ -1775,17 +1765,11 @@ nano_qt::advanced_actions::advanced_actions (nano_qt::wallet & wallet_a) : peers_back (new QPushButton ("Back")), wallet (wallet_a) { - ratio_group->addButton (mnano_unit); - ratio_group->addButton (knano_unit); ratio_group->addButton (nano_unit); ratio_group->addButton (raw_unit); - ratio_group->setId (mnano_unit, 0); - ratio_group->setId (knano_unit, 1); ratio_group->setId (nano_unit, 2); ratio_group->setId (raw_unit, 3); scale_layout->addWidget (scale_label); - scale_layout->addWidget (mnano_unit); - scale_layout->addWidget (knano_unit); scale_layout->addWidget (nano_unit); scale_layout->addWidget (raw_unit); scale_window->setLayout (scale_layout); @@ -1839,25 +1823,11 @@ nano_qt::advanced_actions::advanced_actions (nano_qt::wallet & wallet_a) : layout->addWidget (back); window->setLayout (layout); - QObject::connect (mnano_unit, &QRadioButton::toggled, [this] () { - if (mnano_unit->isChecked ()) - { - QSettings ().setValue (saved_ratio_key, ratio_group->id (mnano_unit)); - this->wallet.change_rendering_ratio (nano::Mxrb_ratio); - } - }); - QObject::connect (knano_unit, &QRadioButton::toggled, [this] () { - if (knano_unit->isChecked ()) - { - QSettings ().setValue (saved_ratio_key, ratio_group->id (knano_unit)); - this->wallet.change_rendering_ratio (nano::kxrb_ratio); - } - }); QObject::connect (nano_unit, &QRadioButton::toggled, [this] () { if (nano_unit->isChecked ()) { QSettings ().setValue (saved_ratio_key, ratio_group->id (nano_unit)); - this->wallet.change_rendering_ratio (nano::xrb_ratio); + this->wallet.change_rendering_ratio (nano::Mxrb_ratio); } }); QObject::connect (raw_unit, &QRadioButton::toggled, [this] () { @@ -1867,17 +1837,23 @@ nano_qt::advanced_actions::advanced_actions (nano_qt::wallet & wallet_a) : this->wallet.change_rendering_ratio (nano::raw_ratio); } }); - auto selected_ratio_id (QSettings ().value (saved_ratio_key, ratio_group->id (mnano_unit)).toInt ()); + auto selected_ratio_id (QSettings ().value (saved_ratio_key, ratio_group->id (nano_unit)).toInt ()); auto selected_ratio_button = ratio_group->button (selected_ratio_id); debug_assert (selected_ratio_button != nullptr); + // Make sure value is not out of bounds + if (selected_ratio_id < 0 || selected_ratio_id > 1) + { + QSettings ().setValue (saved_ratio_key, 0); + selected_ratio_id = 0; + } if (selected_ratio_button) { selected_ratio_button->click (); } else { - mnano_unit->click (); + nano_unit->click (); } QObject::connect (wallet_refresh, &QPushButton::released, [this] () { this->wallet.accounts.refresh (); diff --git a/nano/qt/qt.hpp b/nano/qt/qt.hpp index 4147dbc95d..fd94052bbd 100644 --- a/nano/qt/qt.hpp +++ b/nano/qt/qt.hpp @@ -66,8 +66,6 @@ class advanced_actions QHBoxLayout * scale_layout; QLabel * scale_label; QButtonGroup * ratio_group; - QRadioButton * mnano_unit; - QRadioButton * knano_unit; QRadioButton * nano_unit; QRadioButton * raw_unit; QPushButton * back; diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index 4b26d8a532..2e75bacac7 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -104,7 +104,7 @@ TEST (wallet, startup_balance) wallet->needs_balance_refresh = true; wallet->start (); wallet->application.processEvents (QEventLoop::AllEvents); - ASSERT_EQ ("Balance: 0 NANO", wallet->self.balance_label->text ().toStdString ()); + ASSERT_EQ ("Balance: 0 nano", wallet->self.balance_label->text ().toStdString ()); } TEST (wallet, select_account) diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index c15820a5df..ae0dc837dc 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -2465,17 +2465,17 @@ TEST (rpc, nano_to_raw) request1.put ("action", "nano_to_raw"); request1.put ("amount", "1"); auto response1 (wait_response (system, rpc, request1)); - ASSERT_EQ (nano::xrb_ratio.convert_to (), response1.get ("amount")); + ASSERT_EQ (nano::Mxrb_ratio.convert_to (), response1.get ("amount")); } -TEST (rpc, nano_from_raw) +TEST (rpc, raw_to_nano) { nano::system system; auto node1 = add_ipc_enabled_node (system); auto [rpc, rpc_ctx] = add_rpc (system, node1); boost::property_tree::ptree request1; - request1.put ("action", "nano_from_raw"); - request1.put ("amount", nano::xrb_ratio.convert_to ()); + request1.put ("action", "raw_to_nano"); + request1.put ("amount", nano::Mxrb_ratio.convert_to ()); auto response1 (wait_response (system, rpc, request1)); ASSERT_EQ ("1", response1.get ("amount")); }