diff options
| author | Riccardo Spagni <ric@spagni.net> | 2016-10-04 12:27:33 +0200 |
|---|---|---|
| committer | Riccardo Spagni <ric@spagni.net> | 2016-10-04 12:27:33 +0200 |
| commit | a9a279c9796bfecb1263cf7eafc903acb8f20e8f (patch) | |
| tree | b4596a94b8f31d64f6d1c51784f9166daf82f96d /src | |
| parent | 9bd5a08057561fd7b493d2a546432417ab9e29e6 (diff) | |
| parent | af7f41faa473e2c9661408398e3dc13a1a16c52f (diff) | |
| download | monzero-gui-a9a279c9796bfecb1263cf7eafc903acb8f20e8f.tar.gz monzero-gui-a9a279c9796bfecb1263cf7eafc903acb8f20e8f.tar.xz monzero-gui-a9a279c9796bfecb1263cf7eafc903acb8f20e8f.zip | |
Merge pull request #32
f0d2e58 make splash less resource intensive (Jacob Brydolf)
ad2943f libwallet_api: switched to main repo (Ilya Kitaev)
f402fd9 Wallet::daemonBlockChainHeight(); BC sync progress in GUI (Ilya Kitaev)
7e769b3 Wallet: moneySpent, moneyReceived, newBlock signals (Ilya Kitaev)
Diffstat (limited to 'src')
| -rw-r--r-- | src/libwalletqt/Wallet.cpp | 52 | ||||
| -rw-r--r-- | src/libwalletqt/Wallet.h | 29 |
2 files changed, 68 insertions, 13 deletions
diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 4c6995cb..987f4640 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -10,8 +10,7 @@ #include <QTimer> namespace { - - + static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 60; } class WalletListenerImpl : public Bitmonero::WalletListener @@ -25,18 +24,22 @@ public: virtual void moneySpent(const std::string &txId, uint64_t amount) { - // TODO - Q_UNUSED(txId) - Q_UNUSED(amount) qDebug() << __FUNCTION__; + emit m_wallet->moneySpent(QString::fromStdString(txId), amount); } + virtual void moneyReceived(const std::string &txId, uint64_t amount) { - // TODO - Q_UNUSED(txId) - Q_UNUSED(amount) + qDebug() << __FUNCTION__; + emit m_wallet->moneyReceived(QString::fromStdString(txId), amount); + } + + virtual void newBlock(uint64_t height) + { + // qDebug() << __FUNCTION__; + emit m_wallet->newBlock(height); } virtual void updated() @@ -133,6 +136,23 @@ quint64 Wallet::unlockedBalance() const return m_walletImpl->unlockedBalance(); } +quint64 Wallet::blockChainHeight() const +{ + return m_walletImpl->blockChainHeight(); +} + +quint64 Wallet::daemonBlockChainHeight() const +{ + // cache daemon blockchain height for some time (60 seconds by default) + + if (m_daemonBlockChainHeight == 0 + || m_daemonBlockChainHeightTime.elapsed() / 1000 > m_daemonBlockChainHeightTtl) { + m_daemonBlockChainHeight = m_walletImpl->daemonBlockChainHeight(); + m_daemonBlockChainHeightTime.restart(); + } + return m_daemonBlockChainHeight; +} + bool Wallet::refresh() { bool result = m_walletImpl->refresh(); @@ -146,6 +166,16 @@ void Wallet::refreshAsync() m_walletImpl->refreshAsync(); } +void Wallet::setAutoRefreshInterval(int seconds) +{ + m_walletImpl->setAutoRefreshInterval(seconds); +} + +int Wallet::autoRefreshInterval() const +{ + return m_walletImpl->autoRefreshInterval(); +} + PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, PendingTransaction::Priority priority) @@ -195,7 +225,11 @@ void Wallet::setPaymentId(const QString &paymentId) Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) - : QObject(parent), m_walletImpl(w), m_history(nullptr) + : QObject(parent) + , m_walletImpl(w) + , m_history(nullptr) + , m_daemonBlockChainHeight(0) + , m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS) { m_walletImpl->setListener(new WalletListenerImpl(this)); } diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index feba75e0..703bd186 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -2,11 +2,11 @@ #define WALLET_H #include <QObject> +#include <QTime> #include "wallet/wallet2_api.h" // we need to have an access to the Bitmonero::Wallet::Status enum here; #include "PendingTransaction.h" // we need to have an access to the PendingTransaction::Priority enum here; - namespace Bitmonero { class Wallet; // forward declaration } @@ -28,7 +28,6 @@ class Wallet : public QObject Q_PROPERTY(TransactionHistory * history READ history) Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId) - public: enum Status { Status_Ok = Bitmonero::Wallet::Status_Ok, @@ -77,10 +76,17 @@ public: Q_INVOKABLE void setTrustedDaemon(bool arg); //! returns balance - quint64 balance() const; + Q_INVOKABLE quint64 balance() const; //! returns unlocked balance - quint64 unlockedBalance() const; + Q_INVOKABLE quint64 unlockedBalance() const; + + //! returns current wallet's block height + //! (can be less than daemon's blockchain height when wallet sync in progress) + Q_INVOKABLE quint64 blockChainHeight() const; + + //! returns daemon's blockchain height + Q_INVOKABLE quint64 daemonBlockChainHeight() const; //! refreshes the wallet Q_INVOKABLE bool refresh(); @@ -89,6 +95,12 @@ public: //! refreshes the wallet asynchronously Q_INVOKABLE void refreshAsync(); + //! setup auto-refresh interval in seconds + Q_INVOKABLE void setAutoRefreshInterval(int seconds); + + //! return auto-refresh interval in seconds + Q_INVOKABLE int autoRefreshInterval() const; + //! creates transaction Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, @@ -113,12 +125,18 @@ public: // TODO: setListenter() when it implemented in API signals: + // emitted on every event happened with wallet + // (money sent/received, new block) void updated(); // emitted when refresh process finished (could take a long time) // signalling only after we void refreshed(); + void moneySpent(const QString &txId, quint64 amount); + void moneyReceived(const QString &txId, quint64 amount); + void newBlock(quint64 height); + private: Wallet(Bitmonero::Wallet *w, QObject * parent = 0); @@ -132,6 +150,9 @@ private: // history lifetime managed by wallet; TransactionHistory * m_history; QString m_paymentId; + mutable QTime m_daemonBlockChainHeightTime; + mutable quint64 m_daemonBlockChainHeight; + int m_daemonBlockChainHeightTtl; }; |
