From 850a6944c5149bee847df8aa01365b8cb912af87 Mon Sep 17 00:00:00 2001 From: SergiySW Date: Sun, 16 Jul 2017 19:18:48 +0300 Subject: [PATCH 1/5] "Accounts" button in main menu --- rai/qt/qt.cpp | 121 ++++++++++++++++++++++++++------------------------ rai/qt/qt.hpp | 90 ++++++++++++++++++------------------- 2 files changed, 108 insertions(+), 103 deletions(-) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 980ad265..5464a933 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -112,6 +112,7 @@ void rai_qt::self_pane::refresh_balance () rai_qt::accounts::accounts (rai_qt::wallet & wallet_a) : window (new QWidget), layout (new QVBoxLayout), +wallet_balance_label (new QLabel), model (new QStandardItemModel), view (new QTableView), use_account (new QPushButton ("Use account")), @@ -132,6 +133,7 @@ wallet (wallet_a) view->setModel (model); view->verticalHeader ()->hide (); view->setContextMenuPolicy (Qt::ContextMenuPolicy::CustomContextMenu); + layout->addWidget (wallet_balance_label); layout->addWidget (view); layout->addWidget (use_account); layout->addWidget (create_account); @@ -163,6 +165,7 @@ wallet (wallet_a) account_key_line->clear (); this->wallet.wallet_m->insert_adhoc (key); this->wallet.accounts.refresh (); + this->wallet.accounts.refresh_wallet_balance (); this->wallet.history.refresh (); } else @@ -232,6 +235,34 @@ wallet (wallet_a) }); } }); + refresh_wallet_balance (); +} + + +void rai_qt::accounts::refresh_wallet_balance () +{ + rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, false); + rai::uint128_t balance (0); + rai::uint128_t pending (0); + for (auto i (this->wallet.wallet_m->store.begin (transaction)), j (this->wallet.wallet_m->store.end ()); i != j; ++i) + { + rai::public_key key (i->first); + balance = balance + (this->wallet.node.ledger.account_balance (transaction, key)); + pending = pending + (this->wallet.node.ledger.account_pending (transaction, key)); + } + auto final_text (std::string ("Wallet balance (XRB): ") + (balance / this->wallet.rendering_ratio).convert_to ()); + if (!pending.is_zero ()) + { + final_text += "\nWallet pending: " + (pending / this->wallet.rendering_ratio).convert_to (); + } + wallet_balance_label->setText (QString (final_text.c_str ())); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (60), [this] () + { + this->wallet.application.postEvent (&this->wallet.processor, new eventloop_event ([this] () + { + refresh_wallet_balance (); + })); + }); } void rai_qt::accounts::refresh () @@ -806,6 +837,7 @@ separator (new QFrame), account_history_label (new QLabel ("Account history:")), send_blocks (new QPushButton ("Send")), settings_button (new QPushButton ("Settings")), +accounts_button (new QPushButton ("Accounts")), show_advanced (new QPushButton ("Advanced")), send_blocks_window (new QWidget), send_blocks_layout (new QVBoxLayout), @@ -818,42 +850,43 @@ send_blocks_back (new QPushButton ("Back")), active_status (*this) { update_connected (); - settings.update_locked (true, true); - send_blocks_layout->addWidget (send_account_label); + settings.update_locked (true, true); + send_blocks_layout->addWidget (send_account_label); send_account->setPlaceholderText (rai::zero_key.pub.to_account ().c_str ()); - send_blocks_layout->addWidget (send_account); - send_blocks_layout->addWidget (send_count_label); + send_blocks_layout->addWidget (send_account); + send_blocks_layout->addWidget (send_count_label); send_count->setPlaceholderText ("0"); - send_blocks_layout->addWidget (send_count); - send_blocks_layout->addWidget (send_blocks_send); - send_blocks_layout->addStretch (); - send_blocks_layout->addWidget (send_blocks_back); - send_blocks_layout->setContentsMargins (0, 0, 0, 0); - send_blocks_window->setLayout (send_blocks_layout); + send_blocks_layout->addWidget (send_count); + send_blocks_layout->addWidget (send_blocks_send); + send_blocks_layout->addStretch (); + send_blocks_layout->addWidget (send_blocks_back); + send_blocks_layout->setContentsMargins (0, 0, 0, 0); + send_blocks_window->setLayout (send_blocks_layout); entry_window_layout->addWidget (account_history_label); entry_window_layout->addWidget (history.window); - entry_window_layout->addWidget (send_blocks); + entry_window_layout->addWidget (send_blocks); entry_window_layout->addWidget (settings_button); - entry_window_layout->addWidget (show_advanced); - entry_window_layout->setContentsMargins (0, 0, 0, 0); - entry_window_layout->setSpacing (5); - entry_window->setLayout (entry_window_layout); + entry_window_layout->addWidget (accounts_button); + entry_window_layout->addWidget (show_advanced); + entry_window_layout->setContentsMargins (0, 0, 0, 0); + entry_window_layout->setSpacing (5); + entry_window->setLayout (entry_window_layout); - main_stack->addWidget (entry_window); + main_stack->addWidget (entry_window); status->setAlignment (Qt::AlignHCenter); separator->setFrameShape (QFrame::HLine); separator->setFrameShadow (QFrame::Sunken); client_layout->addWidget (status); - client_layout->addWidget (self.window); + client_layout->addWidget (self.window); client_layout->addWidget (separator); - client_layout->addWidget (main_stack); - client_layout->setSpacing (0); - client_layout->setContentsMargins (0, 0, 0, 0); - client_window->setLayout (client_layout); - client_window->resize (320, 480); + client_layout->addWidget (main_stack); + client_layout->setSpacing (0); + client_layout->setContentsMargins (0, 0, 0, 0); + client_window->setLayout (client_layout); + client_window->resize (320, 480); refresh (); } @@ -867,6 +900,13 @@ void rai_qt::wallet::start () this_l->settings.activate (); } }); + QObject::connect (accounts_button, &QPushButton::released, [this_w] () + { + if (auto this_l = this_w.lock ()) + { + this_l->push_main_stack (this_l->accounts.window); + } + }); QObject::connect (show_advanced, &QPushButton::released, [this_w] () { if (auto this_l = this_w.lock ()) @@ -1365,8 +1405,6 @@ void rai_qt::settings::update_locked (bool invalid, bool vulnerable) rai_qt::advanced_actions::advanced_actions (rai_qt::wallet & wallet_a) : window (new QWidget), layout (new QVBoxLayout), -wallet_balance_label (new QLabel), -accounts (new QPushButton ("Accounts")), show_ledger (new QPushButton ("Ledger")), show_peers (new QPushButton ("Peers")), search_for_receivables (new QPushButton ("Search for receivables")), @@ -1436,8 +1474,6 @@ wallet (wallet_a) peers_layout->setContentsMargins (0, 0, 0, 0); peers_window->setLayout (peers_layout); - layout->addWidget (wallet_balance_label); - layout->addWidget (accounts); layout->addWidget (show_ledger); layout->addWidget (show_peers); layout->addWidget (search_for_receivables); @@ -1474,14 +1510,10 @@ wallet (wallet_a) } }); mrai->click (); - QObject::connect (accounts, &QPushButton::released, [this] () - { - this->wallet.push_main_stack (wallet.accounts.window); - }); QObject::connect (wallet_refresh, &QPushButton::released, [this] () { this->wallet.accounts.refresh (); - refresh_wallet_balance (); + this->wallet.accounts.refresh_wallet_balance (); }); QObject::connect (show_peers, &QPushButton::released, [this] () { @@ -1552,39 +1584,12 @@ wallet (wallet_a) this->wallet.push_main_stack (this->wallet.account_viewer.window); }); refresh_ledger (); - refresh_wallet_balance (); bootstrap->setToolTip ("Multi-connection bootstrap to random peers"); search_for_receivables->setToolTip ("Search for pending blocks"); create_block->setToolTip ("Create block in JSON format"); enter_block->setToolTip ("Enter block in JSON format"); } -void rai_qt::advanced_actions::refresh_wallet_balance () -{ - rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, false); - rai::uint128_t balance (0); - rai::uint128_t pending (0); - for (auto i (this->wallet.wallet_m->store.begin (transaction)), j (this->wallet.wallet_m->store.end ()); i != j; ++i) - { - rai::public_key key (i->first); - balance = balance + (this->wallet.node.ledger.account_balance (transaction, key)); - pending = pending + (this->wallet.node.ledger.account_pending (transaction, key)); - } - auto final_text (std::string ("Wallet balance (XRB): ") + (balance / this->wallet.rendering_ratio).convert_to ()); - if (!pending.is_zero ()) - { - final_text += "\nWallet pending: " + (pending / this->wallet.rendering_ratio).convert_to (); - } - wallet_balance_label->setText (QString (final_text.c_str ())); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (60), [this] () - { - this->wallet.application.postEvent (&this->wallet.processor, new eventloop_event ([this] () - { - refresh_wallet_balance (); - })); - }); -} - void rai_qt::advanced_actions::refresh_peers () { auto list (wallet.node.peers.list ()); diff --git a/rai/qt/qt.hpp b/rai/qt/qt.hpp index 329ace46..c3f3fa32 100644 --- a/rai/qt/qt.hpp +++ b/rai/qt/qt.hpp @@ -51,11 +51,8 @@ namespace rai_qt { { public: advanced_actions (rai_qt::wallet &); - void refresh_wallet_balance (); - QLabel * wallet_balance_label; QWidget * window; QVBoxLayout * layout; - QPushButton * accounts; QPushButton * show_ledger; QPushButton * show_peers; QPushButton * search_for_receivables; @@ -168,21 +165,23 @@ namespace rai_qt { class accounts { public: - accounts (rai_qt::wallet &); - void refresh (); - QWidget * window; - QVBoxLayout * layout; - QStandardItemModel * model; + accounts (rai_qt::wallet &); + void refresh (); + void refresh_wallet_balance (); + QLabel * wallet_balance_label; + QWidget * window; + QVBoxLayout * layout; + QStandardItemModel * model; QTableView * view; QPushButton * use_account; QPushButton * create_account; QPushButton * import_wallet; QPushButton * backup_seed; QFrame * separator; - QLineEdit * account_key_line; - QPushButton * account_key_button; - QPushButton * back; - rai_qt::wallet & wallet; + QLineEdit * account_key_line; + QPushButton * account_key_button; + QPushButton * back; + rai_qt::wallet & wallet; }; class import { @@ -279,12 +278,12 @@ namespace rai_qt { std::set active; rai_qt::wallet & wallet; }; - class wallet : public std::enable_shared_from_this - { - public: - wallet (QApplication &, rai_qt::eventloop_processor &, rai::node &, std::shared_ptr , rai::account &); + class wallet : public std::enable_shared_from_this + { + public: + wallet (QApplication &, rai_qt::eventloop_processor &, rai::node &, std::shared_ptr , rai::account &); void start (); - void refresh (); + void refresh (); void update_connected (); void change_rendering_ratio (rai::uint128_t const &); rai::uint128_t rendering_ratio; @@ -293,42 +292,43 @@ namespace rai_qt { rai::account & account; rai_qt::eventloop_processor & processor; rai_qt::history history; - rai_qt::accounts accounts; + rai_qt::accounts accounts; rai_qt::self_pane self; - rai_qt::settings settings; - rai_qt::advanced_actions advanced; - rai_qt::block_creation block_creation; - rai_qt::block_entry block_entry; + rai_qt::settings settings; + rai_qt::advanced_actions advanced; + rai_qt::block_creation block_creation; + rai_qt::block_entry block_entry; rai_qt::block_viewer block_viewer; rai_qt::account_viewer account_viewer; rai_qt::import import; - - QApplication & application; + + QApplication & application; QLabel * status; - QStackedWidget * main_stack; - - QWidget * client_window; - QVBoxLayout * client_layout; - - QWidget * entry_window; - QVBoxLayout * entry_window_layout; + QStackedWidget * main_stack; + + QWidget * client_window; + QVBoxLayout * client_layout; + + QWidget * entry_window; + QVBoxLayout * entry_window_layout; QFrame * separator; QLabel * account_history_label; - QPushButton * send_blocks; + QPushButton * send_blocks; QPushButton * settings_button; - QPushButton * show_advanced; - - QWidget * send_blocks_window; - QVBoxLayout * send_blocks_layout; - QLabel * send_account_label; - QLineEdit * send_account; - QLabel * send_count_label; - QLineEdit * send_count; - QPushButton * send_blocks_send; - QPushButton * send_blocks_back; + QPushButton * accounts_button; + QPushButton * show_advanced; + + QWidget * send_blocks_window; + QVBoxLayout * send_blocks_layout; + QLabel * send_account_label; + QLineEdit * send_account; + QLabel * send_count_label; + QLineEdit * send_count; + QPushButton * send_blocks_send; + QPushButton * send_blocks_back; rai_qt::status active_status; - void pop_main_stack (); - void push_main_stack (QWidget *); - }; + void pop_main_stack (); + void push_main_stack (QWidget *); + }; } From 765bc6d77d2ec9609890ec40c9f099b6fc4cfd9e Mon Sep 17 00:00:00 2001 From: SergiySW Date: Sun, 16 Jul 2017 22:19:14 +0300 Subject: [PATCH 2/5] GUI: Selectable account & representative --- rai/qt/qt.cpp | 10 ++++++++-- rai/qt/qt.hpp | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 5464a933..c0c6f132 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -78,6 +78,7 @@ wallet (wallet_a) auto font (QFontDatabase::systemFont (QFontDatabase::FixedFont)); font.setPointSize (account_text->font().pointSize()); account_text->setFont (font); + account_text->setTextInteractionFlags(Qt::TextSelectableByMouse); account_layout->addWidget (account_text); account_layout->addWidget (copy_button); account_layout->setContentsMargins (0, 0, 0, 0); @@ -1180,6 +1181,7 @@ retype_password (new QLineEdit), change (new QPushButton ("Set/Change password")), sep2 (new QFrame), representative (new QLabel ("Account representative:")), +current_representative (new QLabel), new_representative (new QLineEdit), change_rep (new QPushButton ("Change representative")), back (new QPushButton ("Back")), @@ -1206,6 +1208,8 @@ wallet (wallet_a) sep2->setFrameShadow (QFrame::Sunken); layout->addWidget (sep2); layout->addWidget (representative); + current_representative->setTextInteractionFlags(Qt::TextSelectableByMouse); + layout->addWidget (current_representative); new_representative->setPlaceholderText (rai::zero_key.pub.to_account ().c_str ()); layout->addWidget (new_representative); layout->addWidget (change_rep); @@ -1275,6 +1279,8 @@ wallet (wallet_a) change_rep->setEnabled (true); show_button_success (*change_rep); change_rep->setText ("Represenative was changed"); + current_representative->setText (QString (representative_l.to_account_split ().c_str ())); + new_representative->clear (); this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () { show_button_ok (*change_rep); @@ -1369,11 +1375,11 @@ void rai_qt::settings::refresh_representative () { auto block (this->wallet.wallet_m->node.store.block_get (transaction, info.rep_block)); assert (block != nullptr); - new_representative->setText (block->representative ().to_account ().c_str ()); + current_representative->setText (QString (block->representative ().to_account_split ().c_str ())); } else { - new_representative->setText (this->wallet.wallet_m->store.representative (transaction).to_account ().c_str ()); + current_representative->setText (this->wallet.wallet_m->store.representative (transaction).to_account_split ().c_str ()); } } diff --git a/rai/qt/qt.hpp b/rai/qt/qt.hpp index c3f3fa32..f0d9aced 100644 --- a/rai/qt/qt.hpp +++ b/rai/qt/qt.hpp @@ -42,6 +42,7 @@ namespace rai_qt { QPushButton * change; QFrame * sep2; QLabel * representative; + QLabel * current_representative; QLineEdit * new_representative; QPushButton * change_rep; QPushButton * back; From 61b8d533659c968b28fc188a7436bed987c14d6f Mon Sep 17 00:00:00 2001 From: SergiySW Date: Mon, 17 Jul 2017 16:28:41 +0300 Subject: [PATCH 3/5] GUI: Correct status at startup if wallet is't protected with password --- rai/qt/qt.cpp | 9 +++++++++ rai/qt/qt.hpp | 1 + 2 files changed, 10 insertions(+) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index c0c6f132..9baa0ac0 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -851,6 +851,7 @@ send_blocks_back (new QPushButton ("Back")), active_status (*this) { update_connected (); + empty_password (); settings.update_locked (true, true); send_blocks_layout->addWidget (send_account_label); send_account->setPlaceholderText (rai::zero_key.pub.to_account ().c_str ()); @@ -1147,6 +1148,13 @@ void rai_qt::wallet::update_connected () } } +void rai_qt::wallet::empty_password () +{ + rai::raw_key empty; + empty.data.clear (); + wallet_m->store.password.value_set (empty); +} + void rai_qt::wallet::change_rendering_ratio (rai::uint128_t const & rendering_ratio_a) { application.postEvent (&processor, new eventloop_event ([this, rendering_ratio_a] () @@ -1238,6 +1246,7 @@ wallet (wallet_a) retype_password->setPlaceholderText ("Retype password"); show_button_success (*change); change->setText ("Password was changed"); + update_locked (false, false); this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () { show_button_ok (*change); diff --git a/rai/qt/qt.hpp b/rai/qt/qt.hpp index f0d9aced..be68ffaa 100644 --- a/rai/qt/qt.hpp +++ b/rai/qt/qt.hpp @@ -286,6 +286,7 @@ namespace rai_qt { void start (); void refresh (); void update_connected (); + void empty_password (); void change_rendering_ratio (rai::uint128_t const &); rai::uint128_t rendering_ratio; rai::node & node; From 2c10bd327c56216b81a54527f0ac21c8434ce57c Mon Sep 17 00:00:00 2001 From: SergiySW Date: Tue, 18 Jul 2017 11:37:29 +0300 Subject: [PATCH 4/5] Default rai_live_network for RAIBLOCKS_GUI build default rai_test_network for RAIBLOCKS_TEST build --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e22b008..a5e198e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,10 +233,15 @@ if (RAIBLOCKS_TEST) add_executable (slow_test rai/slow_test/node.cpp) + SET (ACTIVE_NETWORK rai_test_network CACHE STRING "Selects which network parameters are used") + set_target_properties (core_test slow_test PROPERTIES COMPILE_FLAGS "${PLATFORM_CXX_FLAGS} ${PLATFORM_COMPILE_FLAGS} -DQT_NO_KEYWORDS -DACTIVE_NETWORK=${ACTIVE_NETWORK} -DRAIBLOCKS_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DRAIBLOCKS_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} -DBOOST_ASIO_HAS_STD_ARRAY=1 -DRAIBLOCKS_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}") set_target_properties (core_test slow_test PROPERTIES LINK_FLAGS "${PLATFORM_LINK_FLAGS}") endif (RAIBLOCKS_TEST) +SET (ACTIVE_NETWORK rai_live_network CACHE STRING "Selects which network parameters are used") +set_property (CACHE ACTIVE_NETWORK PROPERTY STRINGS rai_test_network rai_beta_network rai_live_network) + if (RAIBLOCKS_GUI) qt5_add_resources(RES resources.qrc) @@ -269,9 +274,6 @@ add_executable (rai_node rai/rai_node/daemon.hpp rai/rai_node/entry.cpp) -SET (ACTIVE_NETWORK rai_live_network CACHE STRING "Selects which network parameters are used") -set_property (CACHE ACTIVE_NETWORK PROPERTY STRINGS rai_test_network rai_beta_network rai_live_network) - set_target_properties (cryptopp PROPERTIES COMPILE_FLAGS "${PLATFORM_CXX_FLAGS} ${PLATFORM_COMPILE_FLAGS}") set_target_properties (argon2 PROPERTIES COMPILE_FLAGS "${PLATFORM_CXX_FLAGS} ${PLATFORM_COMPILE_FLAGS}") set_target_properties (blake2 PROPERTIES COMPILE_FLAGS "${PLATFORM_C_FLAGS} ${PLATFORM_COMPILE_FLAGS} -D__SSE2__") From eb1a3c7a76054b4897896cd7c6265e182ac6f091 Mon Sep 17 00:00:00 2001 From: SergiySW Date: Fri, 21 Jul 2017 23:52:51 +0300 Subject: [PATCH 5/5] Merge changes from clemahieu/master --- rai/qt/qt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 9baa0ac0..96f00ad3 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -629,7 +629,7 @@ void rai_qt::block_viewer::rebroadcast_action (rai::uint256_union const & hash_a auto block (wallet.node.store.block_get (transaction, hash_a)); if (block != nullptr) { - wallet.node.network.republish_block (*block); + wallet.node.network.republish_block (std::move (block)); auto successor (wallet.node.store.block_successor (transaction, hash_a)); if (!successor.is_zero ()) { @@ -939,7 +939,7 @@ void rai_qt::wallet::start () { if (auto this_l = this_w.lock ()) { - this_l->wallet_m->send_async (this_l->account, account_l, actual, [this_w] (std::unique_ptr block_a) + this_l->wallet_m->send_async (this_l->account, account_l, actual, [this_w] (std::shared_ptr block_a) { if (auto this_l = this_w.lock ()) {