Using observer to get correct wallet unlock information.
This commit is contained in:
parent
2c1970ccd7
commit
3f0de5d5c4
5 changed files with 24 additions and 15 deletions
|
@ -530,12 +530,14 @@ void rai::wallet_store::work_put (MDB_txn * transaction_a, rai::public_key const
|
|||
}
|
||||
|
||||
rai::wallet::wallet (bool & init_a, rai::transaction & transaction_a, rai::node & node_a, std::string const & wallet_a) :
|
||||
lock_observer ([](bool){}),
|
||||
store (init_a, transaction_a, node_a.config.random_representative (), wallet_a),
|
||||
node (node_a)
|
||||
{
|
||||
}
|
||||
|
||||
rai::wallet::wallet (bool & init_a, rai::transaction & transaction_a, rai::node & node_a, std::string const & wallet_a, std::string const & json) :
|
||||
lock_observer ([](bool){}),
|
||||
store (init_a, transaction_a, node_a.config.random_representative (), wallet_a, json),
|
||||
node (node_a)
|
||||
{
|
||||
|
@ -545,15 +547,15 @@ void rai::wallet::enter_initial_password ()
|
|||
{
|
||||
if (store.password.value ().is_zero ())
|
||||
{
|
||||
rai::transaction transaction (store.environment, nullptr, true);
|
||||
if (valid_password ())
|
||||
{
|
||||
rai::transaction transaction (store.environment, nullptr, true);
|
||||
// Newly created wallets have a zero key
|
||||
store.rekey (transaction, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
store.attempt_password (transaction, "");
|
||||
enter_password ("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -577,6 +579,7 @@ bool rai::wallet::enter_password (std::string const & password_a)
|
|||
this_l->search_pending ();
|
||||
});
|
||||
}
|
||||
lock_observer (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ public:
|
|||
void work_update (MDB_txn *, rai::account const &, rai::block_hash const &, uint64_t);
|
||||
uint64_t work_fetch (MDB_txn *, rai::account const &, rai::block_hash const &);
|
||||
bool search_pending ();
|
||||
std::function <void (bool)> lock_observer;
|
||||
rai::wallet_store store;
|
||||
rai::node & node;
|
||||
};
|
||||
|
|
|
@ -448,7 +448,7 @@ send_blocks_back (new QPushButton ("Back")),
|
|||
active_status (*this)
|
||||
{
|
||||
update_connected ();
|
||||
settings.update_locked ();
|
||||
settings.update_locked (true);
|
||||
send_blocks_layout->addWidget (send_account_label);
|
||||
send_account->setPlaceholderText (rai::zero_key.pub.to_base58check ().c_str ());
|
||||
send_blocks_layout->addWidget (send_account);
|
||||
|
@ -616,6 +616,10 @@ active_status (*this)
|
|||
}
|
||||
}));
|
||||
});
|
||||
wallet_m->lock_observer = [this] (bool invalid)
|
||||
{
|
||||
settings.update_locked (invalid);
|
||||
};
|
||||
refresh ();
|
||||
}
|
||||
|
||||
|
@ -743,15 +747,17 @@ wallet (wallet_a)
|
|||
});
|
||||
QObject::connect (unlock, &QPushButton::released, [this] ()
|
||||
{
|
||||
wallet.wallet_m->enter_password (std::string (password->text ().toLocal8Bit ()));
|
||||
update_locked ();
|
||||
if (!wallet.wallet_m->enter_password (std::string (password->text ().toLocal8Bit ())))
|
||||
{
|
||||
password->clear ();
|
||||
}
|
||||
});
|
||||
QObject::connect (lock, &QPushButton::released, [this] ()
|
||||
{
|
||||
rai::uint256_union empty;
|
||||
empty.clear ();
|
||||
wallet.wallet_m->store.password.value_set (empty);
|
||||
update_locked ();
|
||||
update_locked (true);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -760,17 +766,15 @@ void rai_qt::settings::activate ()
|
|||
wallet.push_main_stack (window);
|
||||
}
|
||||
|
||||
void rai_qt::settings::update_locked ()
|
||||
void rai_qt::settings::update_locked (bool invalid)
|
||||
{
|
||||
rai::transaction transaction (wallet.wallet_m->store.environment, nullptr, false);
|
||||
if (wallet.wallet_m->store.valid_password (transaction))
|
||||
if (invalid)
|
||||
{
|
||||
password->clear ();
|
||||
wallet.active_status.erase (rai_qt::status_types::locked);
|
||||
wallet.active_status.insert (rai_qt::status_types::locked);
|
||||
}
|
||||
else
|
||||
{
|
||||
wallet.active_status.insert (rai_qt::status_types::locked);
|
||||
wallet.active_status.erase (rai_qt::status_types::locked);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace rai_qt {
|
|||
public:
|
||||
settings (rai_qt::wallet &);
|
||||
void activate ();
|
||||
void update_locked ();
|
||||
void update_locked (bool);
|
||||
QWidget * window;
|
||||
QVBoxLayout * layout;
|
||||
QLineEdit * password;
|
||||
|
|
|
@ -52,7 +52,7 @@ TEST (wallet, startup_balance)
|
|||
rai::keypair key;
|
||||
wallet_l->insert (key.prv);
|
||||
rai_qt::wallet wallet (*test_application, *system.nodes [0], wallet_l, key.pub);
|
||||
ASSERT_EQ ("Balance: 0", wallet.self.balance_label->text().toStdString ());
|
||||
ASSERT_EQ ("Balance: 0 Mrai", wallet.self.balance_label->text().toStdString ());
|
||||
}
|
||||
|
||||
TEST (wallet, select_account)
|
||||
|
@ -183,7 +183,8 @@ TEST (wallet, enter_password)
|
|||
wallet.settings.new_password->setText ("");
|
||||
QTest::keyClicks (wallet.settings.password, "abc");
|
||||
QTest::mouseClick (wallet.settings.unlock, Qt::LeftButton);
|
||||
ASSERT_EQ ("Status: Running", wallet.status->text ());
|
||||
auto status (wallet.status->text ());
|
||||
ASSERT_EQ ("Status: Running", status);
|
||||
ASSERT_EQ ("", wallet.settings.password->text ());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue