aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/api')
-rw-r--r--src/wallet/api/wallet.cpp49
-rw-r--r--src/wallet/api/wallet.h10
2 files changed, 47 insertions, 12 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 49ccceb13..eefb49e95 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -46,7 +46,9 @@ namespace Bitmonero {
namespace {
// copy-pasted from simplewallet
static const size_t DEFAULT_MIXIN = 4;
- static const int DEFAULT_REFRESH_INTERVAL_SECONDS = 10;
+ static const int DEFAULT_REFRESH_INTERVAL_MILLIS = 1000 * 10;
+ // limit maximum refresh interval as one minute
+ static const int MAX_REFRESH_INTERVAL_MILLIS = 1000 * 60 * 1;
}
struct Wallet2CallbackImpl : public tools::i_wallet2_callback
@@ -75,8 +77,12 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
{
- // TODO;
LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
+
+ if (m_listener) {
+ m_listener->newBlock(height);
+ // m_listener->updated();
+ }
}
virtual void on_money_received(uint64_t height, const cryptonote::transaction& tx, uint64_t amount)
@@ -170,7 +176,7 @@ WalletImpl::WalletImpl(bool testnet)
m_refreshThreadDone = false;
m_refreshEnabled = false;
- m_refreshIntervalSeconds = DEFAULT_REFRESH_INTERVAL_SECONDS;
+ m_refreshIntervalMillis = DEFAULT_REFRESH_INTERVAL_MILLIS;
m_refreshThread = boost::thread([this] () {
this->refreshThreadFunc();
@@ -413,6 +419,27 @@ uint64_t WalletImpl::unlockedBalance() const
return m_wallet->unlocked_balance();
}
+uint64_t WalletImpl::blockChainHeight() const
+{
+ return m_wallet->get_blockchain_current_height();
+}
+
+uint64_t WalletImpl::daemonBlockChainHeight() const
+{
+ std::string err;
+ uint64_t result = m_wallet->get_daemon_blockchain_height(err);
+ if (!err.empty()) {
+ LOG_ERROR(__FUNCTION__ << ": " << err);
+ result = 0;
+ m_errorString = err;
+ m_status = Status_Error;
+
+ } else {
+ m_status = Status_Ok;
+ m_errorString = "";
+ }
+ return result;
+}
bool WalletImpl::refresh()
{
@@ -428,14 +455,20 @@ void WalletImpl::refreshAsync()
m_refreshCV.notify_one();
}
-void WalletImpl::setAutoRefreshInterval(int seconds)
+void WalletImpl::setAutoRefreshInterval(int millis)
{
- m_refreshIntervalSeconds = seconds;
+ if (millis > MAX_REFRESH_INTERVAL_MILLIS) {
+ LOG_ERROR(__FUNCTION__<< ": invalid refresh interval " << millis
+ << " ms, maximum allowed is " << MAX_REFRESH_INTERVAL_MILLIS << " ms");
+ m_refreshIntervalMillis = MAX_REFRESH_INTERVAL_MILLIS;
+ } else {
+ m_refreshIntervalMillis = millis;
+ }
}
int WalletImpl::autoRefreshInterval() const
{
- return m_refreshIntervalSeconds;
+ return m_refreshIntervalMillis;
}
// TODO:
@@ -652,8 +685,8 @@ void WalletImpl::refreshThreadFunc()
LOG_PRINT_L3(__FUNCTION__ << ": waiting for refresh...");
// 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);
+ if (m_refreshIntervalMillis > 0) {
+ boost::posix_time::milliseconds wait_for_ms(m_refreshIntervalMillis);
m_refreshCV.timed_wait(lock, wait_for_ms);
} else {
m_refreshCV.wait(lock);
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 11880d555..d97a8f3b3 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -75,9 +75,11 @@ public:
bool trustedDaemon() const;
uint64_t balance() const;
uint64_t unlockedBalance() const;
+ uint64_t blockChainHeight() const;
+ uint64_t daemonBlockChainHeight() const;
bool refresh();
void refreshAsync();
- void setAutoRefreshInterval(int seconds);
+ void setAutoRefreshInterval(int millis);
int autoRefreshInterval() const;
@@ -105,8 +107,8 @@ private:
friend class TransactionHistoryImpl;
tools::wallet2 * m_wallet;
- std::atomic<int> m_status;
- std::string m_errorString;
+ mutable std::atomic<int> m_status;
+ mutable std::string m_errorString;
std::string m_password;
TransactionHistoryImpl * m_history;
bool m_trustedDaemon;
@@ -116,7 +118,7 @@ private:
// multi-threaded refresh stuff
std::atomic<bool> m_refreshEnabled;
std::atomic<bool> m_refreshThreadDone;
- std::atomic<int> m_refreshIntervalSeconds;
+ std::atomic<int> m_refreshIntervalMillis;
// synchronizing refresh loop;
boost::mutex m_refreshMutex;