Update RPC & QT Wallet to the new units #3386 (#3392)

* Remove knano and mnano references from QT wallet #3386
This commit is contained in:
Shryder 2021-07-26 17:00:48 +00:00 committed by GitHub
commit 88c87f7587
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 44 deletions

View file

@ -105,11 +105,11 @@ void nano::json_handler::process_request (bool unsafe_a)
{ {
mnano_to_raw (nano::kxrb_ratio); 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); 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); mnano_to_raw (nano::xrb_ratio);
} }
@ -121,6 +121,14 @@ void nano::json_handler::process_request (bool unsafe_a)
{ {
mnano_to_raw (); 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") else if (action == "password_valid")
{ {
password_valid (); password_valid ();
@ -2731,6 +2739,7 @@ void nano::json_handler::ledger ()
void nano::json_handler::mnano_from_raw (nano::uint128_t ratio) void nano::json_handler::mnano_from_raw (nano::uint128_t ratio)
{ {
auto amount (amount_impl ()); auto amount (amount_impl ());
response_l.put ("deprecated", "1");
if (!ec) if (!ec)
{ {
auto result (amount.number () / ratio); 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) void nano::json_handler::mnano_to_raw (nano::uint128_t ratio)
{ {
auto amount (amount_impl ()); auto amount (amount_impl ());
response_l.put ("deprecated", "1");
if (!ec) if (!ec)
{ {
auto result (amount.number () * ratio); auto result (amount.number () * ratio);
@ -2757,6 +2767,35 @@ void nano::json_handler::mnano_to_raw (nano::uint128_t ratio)
response_errors (); 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<std::string> ());
}
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<std::string> ());
}
response_errors ();
}
/* /*
* @warning This is an internal/diagnostic RPC, do not rely on its interface being stable * @warning This is an internal/diagnostic RPC, do not rely on its interface being stable
*/ */

View file

@ -75,6 +75,8 @@ public:
void ledger (); void ledger ();
void mnano_to_raw (nano::uint128_t = nano::Mxrb_ratio); void mnano_to_raw (nano::uint128_t = nano::Mxrb_ratio);
void mnano_from_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 ();
void node_id_delete (); void node_id_delete ();
void password_change (); void password_change ();

View file

@ -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 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 balance_str = nano::amount (balance).format_balance (rendering_ratio, 3, false);
auto unit = std::string ("NANO"); auto unit = std::string ("nano");
if (rendering_ratio == nano::kxrb_ratio) if (rendering_ratio == nano::raw_ratio)
{
unit = std::string ("knano");
}
else if (rendering_ratio == nano::xrb_ratio)
{
unit = std::string ("nano");
}
else if (rendering_ratio == nano::raw_ratio)
{ {
unit = std::string ("raw"); unit = std::string ("raw");
} }
@ -1751,8 +1743,6 @@ nano_qt::advanced_actions::advanced_actions (nano_qt::wallet & wallet_a) :
scale_layout (new QHBoxLayout), scale_layout (new QHBoxLayout),
scale_label (new QLabel ("Scale:")), scale_label (new QLabel ("Scale:")),
ratio_group (new QButtonGroup), ratio_group (new QButtonGroup),
mnano_unit (new QRadioButton ("Mnano")),
knano_unit (new QRadioButton ("knano")),
nano_unit (new QRadioButton ("nano")), nano_unit (new QRadioButton ("nano")),
raw_unit (new QRadioButton ("raw")), raw_unit (new QRadioButton ("raw")),
back (new QPushButton ("Back")), back (new QPushButton ("Back")),
@ -1775,17 +1765,11 @@ nano_qt::advanced_actions::advanced_actions (nano_qt::wallet & wallet_a) :
peers_back (new QPushButton ("Back")), peers_back (new QPushButton ("Back")),
wallet (wallet_a) wallet (wallet_a)
{ {
ratio_group->addButton (mnano_unit);
ratio_group->addButton (knano_unit);
ratio_group->addButton (nano_unit); ratio_group->addButton (nano_unit);
ratio_group->addButton (raw_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 (nano_unit, 2);
ratio_group->setId (raw_unit, 3); ratio_group->setId (raw_unit, 3);
scale_layout->addWidget (scale_label); scale_layout->addWidget (scale_label);
scale_layout->addWidget (mnano_unit);
scale_layout->addWidget (knano_unit);
scale_layout->addWidget (nano_unit); scale_layout->addWidget (nano_unit);
scale_layout->addWidget (raw_unit); scale_layout->addWidget (raw_unit);
scale_window->setLayout (scale_layout); scale_window->setLayout (scale_layout);
@ -1839,25 +1823,11 @@ nano_qt::advanced_actions::advanced_actions (nano_qt::wallet & wallet_a) :
layout->addWidget (back); layout->addWidget (back);
window->setLayout (layout); 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] () { QObject::connect (nano_unit, &QRadioButton::toggled, [this] () {
if (nano_unit->isChecked ()) if (nano_unit->isChecked ())
{ {
QSettings ().setValue (saved_ratio_key, ratio_group->id (nano_unit)); 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] () { 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); 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); auto selected_ratio_button = ratio_group->button (selected_ratio_id);
debug_assert (selected_ratio_button != nullptr); 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) if (selected_ratio_button)
{ {
selected_ratio_button->click (); selected_ratio_button->click ();
} }
else else
{ {
mnano_unit->click (); nano_unit->click ();
} }
QObject::connect (wallet_refresh, &QPushButton::released, [this] () { QObject::connect (wallet_refresh, &QPushButton::released, [this] () {
this->wallet.accounts.refresh (); this->wallet.accounts.refresh ();

View file

@ -66,8 +66,6 @@ public:
QHBoxLayout * scale_layout; QHBoxLayout * scale_layout;
QLabel * scale_label; QLabel * scale_label;
QButtonGroup * ratio_group; QButtonGroup * ratio_group;
QRadioButton * mnano_unit;
QRadioButton * knano_unit;
QRadioButton * nano_unit; QRadioButton * nano_unit;
QRadioButton * raw_unit; QRadioButton * raw_unit;
QPushButton * back; QPushButton * back;

View file

@ -104,7 +104,7 @@ TEST (wallet, startup_balance)
wallet->needs_balance_refresh = true; wallet->needs_balance_refresh = true;
wallet->start (); wallet->start ();
wallet->application.processEvents (QEventLoop::AllEvents); 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) TEST (wallet, select_account)

View file

@ -2465,17 +2465,17 @@ TEST (rpc, nano_to_raw)
request1.put ("action", "nano_to_raw"); request1.put ("action", "nano_to_raw");
request1.put ("amount", "1"); request1.put ("amount", "1");
auto response1 (wait_response (system, rpc, request1)); auto response1 (wait_response (system, rpc, request1));
ASSERT_EQ (nano::xrb_ratio.convert_to<std::string> (), response1.get<std::string> ("amount")); ASSERT_EQ (nano::Mxrb_ratio.convert_to<std::string> (), response1.get<std::string> ("amount"));
} }
TEST (rpc, nano_from_raw) TEST (rpc, raw_to_nano)
{ {
nano::system system; nano::system system;
auto node1 = add_ipc_enabled_node (system); auto node1 = add_ipc_enabled_node (system);
auto [rpc, rpc_ctx] = add_rpc (system, node1); auto [rpc, rpc_ctx] = add_rpc (system, node1);
boost::property_tree::ptree request1; boost::property_tree::ptree request1;
request1.put ("action", "nano_from_raw"); request1.put ("action", "raw_to_nano");
request1.put ("amount", nano::xrb_ratio.convert_to<std::string> ()); request1.put ("amount", nano::Mxrb_ratio.convert_to<std::string> ());
auto response1 (wait_response (system, rpc, request1)); auto response1 (wait_response (system, rpc, request1));
ASSERT_EQ ("1", response1.get<std::string> ("amount")); ASSERT_EQ ("1", response1.get<std::string> ("amount"));
} }