mirror of
https://github.com/monero-project/monero.git
synced 2024-11-18 00:37:43 +00:00
wallet2_api: getter and setter for "refresh interval"
This commit is contained in:
parent
cdb6c96f89
commit
d5d0856ce6
4 changed files with 52 additions and 7 deletions
|
@ -428,6 +428,16 @@ void WalletImpl::refreshAsync()
|
||||||
m_refreshCV.notify_one();
|
m_refreshCV.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WalletImpl::setAutoRefreshInterval(int seconds)
|
||||||
|
{
|
||||||
|
m_refreshIntervalSeconds = seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WalletImpl::autoRefreshInterval() const
|
||||||
|
{
|
||||||
|
return m_refreshIntervalSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// 1 - properly handle payment id (add another menthod with explicit 'payment_id' param)
|
// 1 - properly handle payment id (add another menthod with explicit 'payment_id' param)
|
||||||
// 2 - check / design how "Transaction" can be single interface
|
// 2 - check / design how "Transaction" can be single interface
|
||||||
|
@ -640,7 +650,15 @@ void WalletImpl::refreshThreadFunc()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LOG_PRINT_L3(__FUNCTION__ << ": waiting for refresh...");
|
LOG_PRINT_L3(__FUNCTION__ << ": waiting for refresh...");
|
||||||
m_refreshCV.wait(lock);
|
// if auto refresh enabled, we wait for the "m_refreshIntervalSeconds" interval.
|
||||||
|
// if not - we wait forever
|
||||||
|
if (m_refreshIntervalSeconds > 0) {
|
||||||
|
boost::posix_time::milliseconds wait_for_ms(m_refreshIntervalSeconds * 1000);
|
||||||
|
m_refreshCV.timed_wait(lock, wait_for_ms);
|
||||||
|
} else {
|
||||||
|
m_refreshCV.wait(lock);
|
||||||
|
}
|
||||||
|
|
||||||
LOG_PRINT_L3(__FUNCTION__ << ": refresh lock acquired...");
|
LOG_PRINT_L3(__FUNCTION__ << ": refresh lock acquired...");
|
||||||
LOG_PRINT_L3(__FUNCTION__ << ": m_refreshEnabled: " << m_refreshEnabled);
|
LOG_PRINT_L3(__FUNCTION__ << ": m_refreshEnabled: " << m_refreshEnabled);
|
||||||
LOG_PRINT_L3(__FUNCTION__ << ": m_status: " << m_status);
|
LOG_PRINT_L3(__FUNCTION__ << ": m_status: " << m_status);
|
||||||
|
|
|
@ -77,6 +77,11 @@ public:
|
||||||
uint64_t unlockedBalance() const;
|
uint64_t unlockedBalance() const;
|
||||||
bool refresh();
|
bool refresh();
|
||||||
void refreshAsync();
|
void refreshAsync();
|
||||||
|
void setAutoRefreshInterval(int seconds);
|
||||||
|
int autoRefreshInterval() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
|
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
|
||||||
uint64_t amount, uint32_t mixin_count,
|
uint64_t amount, uint32_t mixin_count,
|
||||||
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
|
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
|
||||||
|
|
|
@ -223,10 +223,25 @@ struct Wallet
|
||||||
* @return - true if refreshed successfully;
|
* @return - true if refreshed successfully;
|
||||||
*/
|
*/
|
||||||
virtual bool refresh() = 0;
|
virtual bool refresh() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief refreshAsync - refreshes wallet asynchronously.
|
* @brief refreshAsync - refreshes wallet asynchronously.
|
||||||
*/
|
*/
|
||||||
virtual void refreshAsync() = 0;
|
virtual void refreshAsync() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setAutoRefreshInterval - setup interval for automatic refresh.
|
||||||
|
* @param seconds - interval in seconds. if zero or less than zero - automatic refresh disabled;
|
||||||
|
*/
|
||||||
|
virtual void setAutoRefreshInterval(int seconds) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief autoRefreshInterval - returns automatic refresh interval in seconds
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual int autoRefreshInterval() const = 0;
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored
|
* \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored
|
||||||
* \param dst_addr destination address as string
|
* \param dst_addr destination address as string
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -183,6 +185,7 @@ struct WalletTest2 : public testing::Test
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
|
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -394,6 +397,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
|
||||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
|
||||||
{
|
{
|
||||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||||
|
@ -406,7 +410,8 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
|
||||||
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR_NON_WRITABLE, WALLET_PASS);
|
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR_NON_WRITABLE, WALLET_PASS);
|
||||||
ASSERT_FALSE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
|
ASSERT_FALSE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
|
||||||
|
|
||||||
ASSERT_FALSE(wmgr->closeWallet(wallet1));
|
// "close" always returns true;
|
||||||
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||||
|
|
||||||
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
|
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
|
||||||
ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
|
ASSERT_TRUE(wallet1->status() == Bitmonero::Wallet::Status_Ok);
|
||||||
|
@ -416,6 +421,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
|
TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
|
||||||
{
|
{
|
||||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||||
|
@ -792,6 +798,7 @@ struct MyWalletListener : public Bitmonero::WalletListener
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
TEST_F(WalletTest2, WalletCallBackRefreshedSync)
|
TEST_F(WalletTest2, WalletCallBackRefreshedSync)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -800,11 +807,12 @@ TEST_F(WalletTest2, WalletCallBackRefreshedSync)
|
||||||
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||||
ASSERT_TRUE(wallet_src_listener->refresh_triggered);
|
ASSERT_TRUE(wallet_src_listener->refresh_triggered);
|
||||||
ASSERT_TRUE(wallet_src->connected());
|
ASSERT_TRUE(wallet_src->connected());
|
||||||
// std::chrono::seconds wait_for = std::chrono::seconds(60*3);
|
std::chrono::seconds wait_for = std::chrono::seconds(60*3);
|
||||||
// std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
||||||
// wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
||||||
wmgr->closeWallet(wallet_src);
|
wmgr->closeWallet(wallet_src);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
|
TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
|
||||||
|
@ -908,10 +916,9 @@ TEST_F(WalletTest2, WalletCallbackReceived)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
// Bitmonero::WalletManagerFactory::setLogLevel(Bitmonero::WalletManagerFactory::LogLevel_Max);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue