Scaling belongs in the gui portion since it's really a component of rendering.
This commit is contained in:
parent
6ddeee6a7f
commit
16e9b905ef
6 changed files with 48 additions and 42 deletions
|
@ -822,8 +822,7 @@ bootstrap (*service_a, port_a, *this),
|
|||
processor (*this),
|
||||
transactions (*this),
|
||||
peers (network.endpoint ()),
|
||||
service (processor_a),
|
||||
scale ("100000000000000000000")
|
||||
service (processor_a)
|
||||
{
|
||||
if (!init_a.error ())
|
||||
{
|
||||
|
@ -3828,16 +3827,6 @@ bool rai::publish_req::operator == (rai::publish_req const & other_a) const
|
|||
return work == other_a.work && *block == *other_a.block;
|
||||
}
|
||||
|
||||
uint64_t rai::client::scale_down (rai::uint128_t const & amount_a)
|
||||
{
|
||||
return (amount_a / scale).convert_to <uint64_t> ();
|
||||
}
|
||||
|
||||
rai::uint128_t rai::client::scale_up (uint64_t amount_a)
|
||||
{
|
||||
return scale * amount_a;
|
||||
}
|
||||
|
||||
rai::work::work () :
|
||||
entry_requirement (8 * 1024),
|
||||
iteration_requirement (8 * 1024)
|
||||
|
|
|
@ -603,8 +603,6 @@ namespace rai {
|
|||
std::shared_ptr <rai::client> shared ();
|
||||
bool is_representative ();
|
||||
void representative_vote (rai::election &, rai::block const &);
|
||||
uint64_t scale_down (rai::uint128_t const &);
|
||||
rai::uint128_t scale_up (uint64_t);
|
||||
rai::log log;
|
||||
rai::address representative;
|
||||
rai::block_store store;
|
||||
|
@ -618,7 +616,6 @@ namespace rai {
|
|||
rai::transactions transactions;
|
||||
rai::peer_container peers;
|
||||
rai::processor_service & service;
|
||||
rai::uint128_t scale;
|
||||
};
|
||||
class system
|
||||
{
|
||||
|
|
|
@ -65,7 +65,8 @@ peers_layout (new QVBoxLayout),
|
|||
peers_model (new QStringListModel),
|
||||
peers_view (new QListView),
|
||||
peers_refresh (new QPushButton ("Refresh")),
|
||||
peers_back (new QPushButton ("Back"))
|
||||
peers_back (new QPushButton ("Back")),
|
||||
scale ("100000000000000000000")
|
||||
{
|
||||
send_blocks_layout->addWidget (send_address_label);
|
||||
send_blocks_layout->addWidget (send_address);
|
||||
|
@ -276,8 +277,8 @@ peers_back (new QPushButton ("Back"))
|
|||
try
|
||||
{
|
||||
auto scaled (std::stoull (coins_text_narrow));
|
||||
rai::uint128_t coins (client_m.scale_up (scaled));
|
||||
if (coins / client_m.scale == scaled)
|
||||
rai::uint128_t coins (scale_up (scaled));
|
||||
if (coins / scale == scaled)
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor (QPalette::Text, Qt::black);
|
||||
|
@ -393,7 +394,7 @@ void rai_qt::client::refresh_ledger ()
|
|||
std::string account;
|
||||
i->first.encode_base58check (account);
|
||||
items.push_back (new QStandardItem (QString (account.c_str ())));
|
||||
items.push_back (new QStandardItem (QString (std::to_string (client_m.scale_down (client_m.ledger.balance (i->second.hash))).c_str ())));
|
||||
items.push_back (new QStandardItem (QString (std::to_string (scale_down (client_m.ledger.balance (i->second.hash))).c_str ())));
|
||||
std::string block_hash;
|
||||
i->second.hash.encode_hex (block_hash);
|
||||
items.push_back (new QStandardItem (QString (block_hash.c_str ())));
|
||||
|
@ -414,11 +415,11 @@ void rai_qt::client::refresh_wallet ()
|
|||
items.push_back (new QStandardItem (QString (account.c_str ())));
|
||||
auto account_balance (client_m.ledger.account_balance (key));
|
||||
balance += account_balance;
|
||||
auto balance (std::to_string (client_m.scale_down (account_balance)));
|
||||
auto balance (std::to_string (scale_down (account_balance)));
|
||||
items.push_back (new QStandardItem (balance.c_str ()));
|
||||
wallet_model->appendRow (items);
|
||||
}
|
||||
balance_label->setText (QString ((std::string ("Balance: ") + std::to_string (client_m.scale_down (balance))).c_str ()));
|
||||
balance_label->setText (QString ((std::string ("Balance: ") + std::to_string (scale_down (balance))).c_str ()));
|
||||
}
|
||||
|
||||
rai_qt::client::~client ()
|
||||
|
@ -543,4 +544,14 @@ void rai_qt::enter_password::update_label ()
|
|||
valid->setStyleSheet ("QLabel { color: red }");
|
||||
valid->setText ("Password: INVALID");
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t rai_qt::client::scale_down (rai::uint128_t const & amount_a)
|
||||
{
|
||||
return (amount_a / scale).convert_to <uint64_t> ();
|
||||
}
|
||||
|
||||
rai::uint128_t rai_qt::client::scale_up (uint64_t amount_a)
|
||||
{
|
||||
return scale * amount_a;
|
||||
}
|
|
@ -117,6 +117,9 @@ namespace rai_qt {
|
|||
|
||||
void pop_main_stack ();
|
||||
void push_main_stack (QWidget *);
|
||||
rai::uint128_t const scale;
|
||||
uint64_t scale_down (rai::uint128_t const &);
|
||||
rai::uint128_t scale_up (uint64_t);
|
||||
private:
|
||||
void refresh_wallet ();
|
||||
void refresh_ledger ();
|
||||
|
|
|
@ -127,7 +127,7 @@ TEST (client, send)
|
|||
system.service->poll_one ();
|
||||
system.processor.poll_one ();
|
||||
}
|
||||
ASSERT_EQ (2 * client.client_m.scale, client.client_m.ledger.account_balance (key1.pub));
|
||||
ASSERT_EQ (2 * client.scale, client.client_m.ledger.account_balance (key1.pub));
|
||||
QTest::mouseClick (client.send_blocks_back, Qt::LeftButton);
|
||||
QTest::mouseClick (client.show_ledger, Qt::LeftButton);
|
||||
QTest::mouseClick (client.ledger_refresh, Qt::LeftButton);
|
||||
|
@ -135,4 +135,30 @@ TEST (client, send)
|
|||
ASSERT_EQ (3, client.ledger_model->columnCount ());
|
||||
auto item (client.ledger_model->itemFromIndex (client.ledger_model->index (1, 1)));
|
||||
ASSERT_EQ ("2", item->text ().toStdString ());
|
||||
}
|
||||
|
||||
TEST (client, scaling)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
int argc (0);
|
||||
QApplication application (argc, nullptr);
|
||||
rai_qt::client client (application, *system.clients [0]);
|
||||
auto max (std::numeric_limits <rai::uint128_t>::max ());
|
||||
auto down (client.scale_down (max));
|
||||
auto up1 (client.scale_up (down));
|
||||
auto up2 (client.scale_up (down - 1));
|
||||
ASSERT_LT (up2, up1);
|
||||
ASSERT_EQ (up1 - up2, client.scale);
|
||||
}
|
||||
|
||||
TEST (client, scale_num)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
int argc (0);
|
||||
QApplication application (argc, nullptr);
|
||||
rai_qt::client client (application, *system.clients [0]);
|
||||
rai::uint128_t num ("100000000000000000000000000000000000000");
|
||||
auto down (client.scale_down (num));
|
||||
auto up (client.scale_up (down));
|
||||
ASSERT_EQ (num, up);
|
||||
}
|
|
@ -172,26 +172,6 @@ TEST (client, multi_account_send_atomicness)
|
|||
system.clients [0]->transactions.send (key1.pub, std::numeric_limits<rai::uint128_t>::max () / 2 + std::numeric_limits<rai::uint128_t>::max () / 4);
|
||||
}
|
||||
|
||||
TEST (client, scaling)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
auto max (std::numeric_limits <rai::uint128_t>::max ());
|
||||
auto down (system.clients [0]->scale_down (max));
|
||||
auto up1 (system.clients [0]->scale_up (down));
|
||||
auto up2 (system.clients [0]->scale_up (down - 1));
|
||||
ASSERT_LT (up2, up1);
|
||||
ASSERT_EQ (up1 - up2, system.clients [0]->scale);
|
||||
}
|
||||
|
||||
TEST (client, scale_num)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
rai::uint128_t num ("100000000000000000000000000000000000000");
|
||||
auto down (system.clients [0]->scale_down (num));
|
||||
auto up (system.clients [0]->scale_up (down));
|
||||
ASSERT_EQ (num, up);
|
||||
}
|
||||
|
||||
TEST (client, receive_gap)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue