mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-27 05:13:25 +01:00
Merge pull request #1655
b14d109b
update wallet api tests (Jaquee)0cc50bdd
GUI: Improved refresh performance (Jaquee)805625b5
wallet api: Remove initAsync() and don't start refresh automatically on init (Jaquee)031b060a
wallet2::init() - disconnect before init if connected Makes it possible for GUI to reinit with new daemon without closing and reopening wallet. (Jaquee)
This commit is contained in:
commit
3473af00ad
@ -85,11 +85,14 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
|||||||
|
|
||||||
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
|
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
|
||||||
{
|
{
|
||||||
//LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
|
// Don't flood the GUI with signals. On fast refresh - send signal every 1000th block
|
||||||
|
// get_refresh_from_block_height() returns the blockheight from when the wallet was
|
||||||
|
// created or the restore height specified when wallet was recovered
|
||||||
|
if(height >= m_wallet->m_wallet->get_refresh_from_block_height() || height % 1000 == 0) {
|
||||||
|
// LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
|
||||||
if (m_listener) {
|
if (m_listener) {
|
||||||
m_listener->newBlock(height);
|
m_listener->newBlock(height);
|
||||||
// m_listener->updated();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +518,6 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed)
|
|||||||
try {
|
try {
|
||||||
m_wallet->set_seed_language(old_language);
|
m_wallet->set_seed_language(old_language);
|
||||||
m_wallet->generate(path, "", recovery_key, true, false);
|
m_wallet->generate(path, "", recovery_key, true, false);
|
||||||
// TODO: wallet->init(daemon_address);
|
|
||||||
|
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
m_status = Status_Critical;
|
m_status = Status_Critical;
|
||||||
@ -535,7 +537,7 @@ bool WalletImpl::close()
|
|||||||
if (status() != Status_Critical)
|
if (status() != Status_Critical)
|
||||||
m_wallet->store();
|
m_wallet->store();
|
||||||
else
|
else
|
||||||
LOG_PRINT_L3("Status_Critical - not storing wallet");
|
LOG_ERROR("Status_Critical - not storing wallet");
|
||||||
LOG_PRINT_L1("wallet::store done");
|
LOG_PRINT_L1("wallet::store done");
|
||||||
LOG_PRINT_L1("Calling wallet::stop...");
|
LOG_PRINT_L1("Calling wallet::stop...");
|
||||||
m_wallet->stop();
|
m_wallet->stop();
|
||||||
@ -646,19 +648,7 @@ string WalletImpl::keysFilename() const
|
|||||||
bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit)
|
bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit)
|
||||||
{
|
{
|
||||||
clearStatus();
|
clearStatus();
|
||||||
if (!doInit(daemon_address, upper_transaction_size_limit))
|
return doInit(daemon_address, upper_transaction_size_limit);
|
||||||
return false;
|
|
||||||
bool result = this->refresh();
|
|
||||||
// enabling background refresh thread
|
|
||||||
startRefresh();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WalletImpl::initAsync(const string &daemon_address, uint64_t upper_transaction_size_limit)
|
|
||||||
{
|
|
||||||
clearStatus();
|
|
||||||
doInit(daemon_address, upper_transaction_size_limit);
|
|
||||||
startRefresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WalletImpl::setRefreshFromBlockHeight(uint64_t refresh_from_block_height)
|
void WalletImpl::setRefreshFromBlockHeight(uint64_t refresh_from_block_height)
|
||||||
@ -1323,8 +1313,8 @@ void WalletImpl::doRefresh()
|
|||||||
|
|
||||||
void WalletImpl::startRefresh()
|
void WalletImpl::startRefresh()
|
||||||
{
|
{
|
||||||
LOG_PRINT_L2(__FUNCTION__ << ": refresh started/resumed...");
|
|
||||||
if (!m_refreshEnabled) {
|
if (!m_refreshEnabled) {
|
||||||
|
LOG_PRINT_L2(__FUNCTION__ << ": refresh started/resumed...");
|
||||||
m_refreshEnabled = true;
|
m_refreshEnabled = true;
|
||||||
m_refreshCV.notify_one();
|
m_refreshCV.notify_one();
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,7 @@ public:
|
|||||||
bool store(const std::string &path);
|
bool store(const std::string &path);
|
||||||
std::string filename() const;
|
std::string filename() const;
|
||||||
std::string keysFilename() const;
|
std::string keysFilename() const;
|
||||||
bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
|
bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0);
|
||||||
void initAsync(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
|
|
||||||
bool connectToDaemon();
|
bool connectToDaemon();
|
||||||
ConnectionStatus connected() const;
|
ConnectionStatus connected() const;
|
||||||
void setTrustedDaemon(bool arg);
|
void setTrustedDaemon(bool arg);
|
||||||
@ -135,7 +134,6 @@ private:
|
|||||||
bool isNewWallet() const;
|
bool isNewWallet() const;
|
||||||
bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
|
bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PendingTransactionImpl;
|
friend class PendingTransactionImpl;
|
||||||
friend class UnsignedTransactionImpl;
|
friend class UnsignedTransactionImpl;
|
||||||
|
@ -487,6 +487,8 @@ std::pair<std::unique_ptr<wallet2>, password_container> wallet2::make_new(const
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool wallet2::init(std::string daemon_address, uint64_t upper_transaction_size_limit)
|
bool wallet2::init(std::string daemon_address, uint64_t upper_transaction_size_limit)
|
||||||
{
|
{
|
||||||
|
if(m_http_client.is_connected())
|
||||||
|
m_http_client.disconnect();
|
||||||
m_upper_transaction_size_limit = upper_transaction_size_limit;
|
m_upper_transaction_size_limit = upper_transaction_size_limit;
|
||||||
m_daemon_address = std::move(daemon_address);
|
m_daemon_address = std::move(daemon_address);
|
||||||
return m_http_client.set_server(get_daemon_address());
|
return m_http_client.set_server(get_daemon_address());
|
||||||
|
@ -332,26 +332,16 @@ struct Wallet
|
|||||||
*/
|
*/
|
||||||
virtual std::string keysFilename() const = 0;
|
virtual std::string keysFilename() const = 0;
|
||||||
/*!
|
/*!
|
||||||
* \brief init - initializes wallet with daemon connection params. implicitly connects to the daemon
|
* \brief init - initializes wallet with daemon connection params.
|
||||||
* and refreshes the wallet. "refreshed" callback will be invoked. if daemon_address is
|
* if daemon_address is local address, "trusted daemon" will be set to true forcibly
|
||||||
* local address, "trusted daemon" will be set to true forcibly
|
* startRefresh() should be called when wallet is initialized.
|
||||||
*
|
*
|
||||||
* \param daemon_address - daemon address in "hostname:port" format
|
* \param daemon_address - daemon address in "hostname:port" format
|
||||||
* \param upper_transaction_size_limit
|
* \param upper_transaction_size_limit
|
||||||
* \return - true if initialized and refreshed successfully
|
* \return - true on success
|
||||||
*/
|
*/
|
||||||
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0;
|
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0;
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief init - initalizes wallet asynchronously. logic is the same as "init" but returns immediately.
|
|
||||||
* "refreshed" callback will be invoked.
|
|
||||||
*
|
|
||||||
* \param daemon_address - daemon address in "hostname:port" format
|
|
||||||
* \param upper_transaction_size_limit
|
|
||||||
* \return - true if initialized and refreshed successfully
|
|
||||||
*/
|
|
||||||
virtual void initAsync(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief createWatchOnly - Creates a watch only wallet
|
* \brief createWatchOnly - Creates a watch only wallet
|
||||||
* \param path - where to store the wallet
|
* \param path - where to store the wallet
|
||||||
|
@ -897,7 +897,8 @@ TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
|
|||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(20);
|
std::chrono::seconds wait_for = std::chrono::seconds(20);
|
||||||
std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
||||||
wallet_src->initAsync(TESTNET_DAEMON_ADDRESS, 0);
|
wallet_src->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
|
wallet_src->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
||||||
std::cerr << "TEST: refresh lock acquired...\n";
|
std::cerr << "TEST: refresh lock acquired...\n";
|
||||||
@ -1050,8 +1051,8 @@ TEST_F(WalletManagerMainnetTest, CreateAndRefreshWalletMainNetAsync)
|
|||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
||||||
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
||||||
wallet->initAsync(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
// wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
wallet_listener->cv_refresh.wait_for(lock, wait_for);
|
wallet_listener->cv_refresh.wait_for(lock, wait_for);
|
||||||
std::cerr << "TEST: refresh lock acquired...\n";
|
std::cerr << "TEST: refresh lock acquired...\n";
|
||||||
@ -1076,8 +1077,8 @@ TEST_F(WalletManagerMainnetTest, OpenAndRefreshWalletMainNetAsync)
|
|||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
||||||
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
||||||
wallet->initAsync(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
// wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
wallet_listener->cv_refresh.wait_for(lock, wait_for);
|
wallet_listener->cv_refresh.wait_for(lock, wait_for);
|
||||||
std::cerr << "TEST: refresh lock acquired...\n";
|
std::cerr << "TEST: refresh lock acquired...\n";
|
||||||
@ -1110,8 +1111,8 @@ TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync)
|
|||||||
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
||||||
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
||||||
wallet->initAsync(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
// wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
|
|
||||||
// here we wait for 120 seconds and test if wallet doesn't syncrnonize blockchain completely,
|
// here we wait for 120 seconds and test if wallet doesn't syncrnonize blockchain completely,
|
||||||
|
Loading…
Reference in New Issue
Block a user