From 1e3b666a192b671468aab71b1b8d410495b39701 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Thu, 20 Apr 2017 13:16:47 -0500 Subject: [PATCH] Constructing eventloop_processor before qt_wallet. --- rai/qt/qt.cpp | 3 ++- rai/qt/qt.hpp | 4 ++-- rai/qt_system/entry.cpp | 3 ++- rai/qt_test/qt.cpp | 49 ++++++++++++++++++++-------------------- rai/rai_wallet/entry.cpp | 3 ++- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 359b1f1a3..d4c543018 100644 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -710,11 +710,12 @@ std::string rai_qt::status::color () return result; } -rai_qt::wallet::wallet (QApplication & application_a, rai::node & node_a, std::shared_ptr wallet_a, rai::account & account_a) : +rai_qt::wallet::wallet (QApplication & application_a, rai_qt::eventloop_processor & processor_a, rai::node & node_a, std::shared_ptr wallet_a, rai::account & account_a) : rendering_ratio (rai::Mrai_ratio), node (node_a), wallet_m (wallet_a), account (account_a), +processor (processor_a), history (node.ledger, account, rendering_ratio), accounts (*this), self (*this, account_a), diff --git a/rai/qt/qt.hpp b/rai/qt/qt.hpp index 6ba686cc2..62ddb0ea1 100644 --- a/rai/qt/qt.hpp +++ b/rai/qt/qt.hpp @@ -275,7 +275,7 @@ namespace rai_qt { class wallet : public std::enable_shared_from_this { public: - wallet (QApplication &, rai::node &, std::shared_ptr , rai::account &); + wallet (QApplication &, rai_qt::eventloop_processor &, rai::node &, std::shared_ptr , rai::account &); void start (); void refresh (); void update_connected (); @@ -284,7 +284,7 @@ namespace rai_qt { rai::node & node; std::shared_ptr wallet_m; rai::account & account; - rai_qt::eventloop_processor processor; + rai_qt::eventloop_processor & processor; rai_qt::history history; rai_qt::accounts accounts; rai_qt::self_pane self; diff --git a/rai/qt_system/entry.cpp b/rai/qt_system/entry.cpp index 5eb6fe3da..cd741a83b 100644 --- a/rai/qt_system/entry.cpp +++ b/rai/qt_system/entry.cpp @@ -6,6 +6,7 @@ int main (int argc, char ** argv) { QApplication application (argc, argv); + rai_qt::eventloop_processor processor; static int count (16); rai::system system (24000, count); std::unique_ptr client_tabs (new QTabWidget); @@ -17,7 +18,7 @@ int main (int argc, char ** argv) auto wallet (system.nodes [i]->wallets.create (wallet_id)); rai::keypair key; wallet->insert_adhoc (key.prv); - guis.push_back (std::unique_ptr (new rai_qt::wallet (application, *system.nodes [i], wallet, key.pub))); + guis.push_back (std::unique_ptr (new rai_qt::wallet (application, processor, *system.nodes [i], wallet, key.pub))); client_tabs->addTab (guis.back ()->client_window, boost::str (boost::format ("Wallet %1%") % i).c_str ()); } client_tabs->show (); diff --git a/rai/qt_test/qt.cpp b/rai/qt_test/qt.cpp index 3ff08283f..7ffc17c69 100644 --- a/rai/qt_test/qt.cpp +++ b/rai/qt_test/qt.cpp @@ -9,13 +9,14 @@ #include extern QApplication * test_application; +rai_qt::eventloop_processor processor; TEST (wallet, construction) { rai::system system (24000, 1); auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); auto key (wallet_l->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, *system.nodes [0], wallet_l, key)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key)); wallet->start (); ASSERT_EQ (key.to_account_split (), wallet->self.account_text->text ().toStdString ()); ASSERT_EQ (1, wallet->accounts.model->rowCount ()); @@ -29,7 +30,7 @@ TEST (wallet, status) auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); rai::keypair key; wallet_l->insert_adhoc (key.prv); - auto wallet (std::make_shared (*test_application, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); wallet->start (); ASSERT_EQ ("Status: Disconnected", wallet->status->text ().toStdString ()); system.nodes [0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000)); @@ -56,7 +57,7 @@ TEST (wallet, startup_balance) auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); rai::keypair key; wallet_l->insert_adhoc (key.prv); - auto wallet (std::make_shared (*test_application, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); wallet->start (); ASSERT_EQ ("Balance: 0", wallet->self.balance_label->text().toStdString ()); } @@ -67,7 +68,7 @@ TEST (wallet, select_account) auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); rai::public_key key1 (wallet_l->deterministic_insert ()); rai::public_key key2 (wallet_l->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, *system.nodes [0], wallet_l, key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key1)); wallet->start (); ASSERT_EQ (key1, wallet->account); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -87,7 +88,7 @@ TEST (wallet, main) auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); rai::keypair key; wallet_l->insert_adhoc (key.prv); - auto wallet (std::make_shared (*test_application, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); wallet->start (); ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ()); QTest::mouseClick (wallet->send_blocks, Qt::LeftButton); @@ -120,7 +121,7 @@ TEST (wallet, password_change) rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->settings_button, Qt::LeftButton); { @@ -155,7 +156,7 @@ TEST (client, password_nochange) rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->settings_button, Qt::LeftButton); auto iterations (0); @@ -200,7 +201,7 @@ TEST (wallet, enter_password) rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.password)); ASSERT_NE (-1, wallet->settings.lock_layout->indexOf (wallet->settings.unlock)); @@ -233,7 +234,7 @@ TEST (wallet, send) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::public_key key1 (system.wallet (1)->insert_adhoc (rai::keypair ().prv)); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->send_blocks, Qt::LeftButton); QTest::keyClicks (wallet->send_account, key1.to_account ().c_str ()); @@ -265,7 +266,7 @@ TEST (wallet, send_locked) rai::keypair key1; system.wallet (0)->enter_password ("0"); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->send_blocks, Qt::LeftButton); QTest::keyClicks (wallet->send_account, key1.pub.to_account ().c_str ()); @@ -291,7 +292,7 @@ TEST (wallet, process_block) rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); ASSERT_EQ ("Process", wallet->block_entry.process->text ()); ASSERT_EQ ("Back", wallet->block_entry.back->text ()); @@ -322,7 +323,7 @@ TEST (wallet, create_send) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); wallet->client_window->show (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -356,7 +357,7 @@ TEST (wallet, create_open_receive) ASSERT_NE (latest1, latest2); system.wallet (0)->insert_adhoc (key.prv); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); wallet->client_window->show (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -398,7 +399,7 @@ TEST (wallet, create_change) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); wallet->client_window->show (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -452,7 +453,7 @@ TEST (wallet, startup_work) rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); uint64_t work1; @@ -485,7 +486,7 @@ TEST (wallet, block_viewer) rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_NE (-1, wallet->advanced.layout->indexOf (wallet->advanced.block_viewer)); @@ -517,7 +518,7 @@ TEST (wallet, import) stream.open (path.string ().c_str ()); stream << json; } - auto wallet (std::make_shared (*test_application, *system.nodes [1], system.wallet (1), key2.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [1], system.wallet (1), key2.pub)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -545,7 +546,7 @@ TEST (wallet, republish) ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (transaction, block).code); } auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -568,7 +569,7 @@ TEST (wallet, ignore_empty_adhoc) rai::system system (24000, 1); rai::keypair key1; system.wallet (0)->insert_adhoc (key1.prv); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), key1.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1.pub)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -595,7 +596,7 @@ TEST (wallet, change_seed) rai::raw_key seed3; system.wallet (0)->store.seed (seed3, rai::transaction (system.wallet (0)->store.environment, nullptr, false)); auto wallet_key (key1); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), wallet_key)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), wallet_key)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -636,7 +637,7 @@ TEST (wallet, seed_work_generation) { rai::system system (24000, 1); auto key1 (system.wallet (0)->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -667,7 +668,7 @@ TEST (wallet, backup_seed) { rai::system system (24000, 1); auto key1 (system.wallet (0)->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -684,7 +685,7 @@ TEST (wallet, import_locked) rai::system system (24000, 1); auto key1 (system.wallet (0)->deterministic_insert ()); system.wallet (0)->store.rekey (rai::transaction (system.wallet (0)->store.environment, nullptr, true), "1"); - auto wallet (std::make_shared (*test_application, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -711,7 +712,7 @@ TEST (wallet, synchronizing) rai::system system0 (24000, 1); rai::system system1 (24001, 1); auto key1 (system0.wallet (0)->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, *system0.nodes [0], system0.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system0.nodes [0], system0.wallet (0), key1)); wallet->start (); { rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true); diff --git a/rai/rai_wallet/entry.cpp b/rai/rai_wallet/entry.cpp index 7fee623d1..38ee635f6 100755 --- a/rai/rai_wallet/entry.cpp +++ b/rai/rai_wallet/entry.cpp @@ -191,6 +191,7 @@ bool update_config (qt_wallet_config & config_a, boost::filesystem::path const & int run_wallet (QApplication & application, int argc, char * const * argv) { + rai_qt::eventloop_processor processor; auto working (rai::working_path ()); boost::filesystem::create_directories (working); qt_wallet_config config (working); @@ -245,7 +246,7 @@ int run_wallet (QApplication & application, int argc, char * const * argv) { rpc.start (); } - auto gui (std::make_shared (application, *node, wallet, config.account)); + auto gui (std::make_shared (application, processor, *node, wallet, config.account)); gui->start (); gui->client_window->show (); rai::thread_runner runner (service, node->config.io_threads);