From 7e769b3a87c9eda69d0506c9ce13859bafc50951 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 23 Sep 2016 23:51:24 +0300 Subject: [PATCH 1/4] Wallet: moneySpent, moneyReceived, newBlock signals --- get_libwallet_api.sh | 6 ++++-- src/libwalletqt/Wallet.cpp | 16 ++++++++++------ src/libwalletqt/Wallet.h | 6 ++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/get_libwallet_api.sh b/get_libwallet_api.sh index 7ef6f0ff..0cc850ed 100755 --- a/get_libwallet_api.sh +++ b/get_libwallet_api.sh @@ -1,8 +1,10 @@ #!/bin/bash -MONERO_URL=https://github.com/monero-project/monero.git -MONERO_BRANCH=master +# MONERO_URL=https://github.com/monero-project/monero.git +# MONERO_BRANCH=master +MONERO_URL=https://github.com/mbg033/monero.git +MONERO_BRANCH=develop # thanks to SO: http://stackoverflow.com/a/20283965/4118915 CPU_CORE_COUNT=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) pushd $(pwd) diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 4c6995cb..034aa1de 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -25,18 +25,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() diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index feba75e0..faa01263 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -113,12 +113,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); From f402fd9e7d26f5b2bc56c55322a7a97ebb3dbe66 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Mon, 26 Sep 2016 22:55:25 +0300 Subject: [PATCH 2/4] Wallet::daemonBlockChainHeight(); BC sync progress in GUI --- components/ProcessingSplash.qml | 23 ++++++++++++++------ main.cpp | 2 +- main.qml | 14 +++++++++++- src/libwalletqt/Wallet.cpp | 38 +++++++++++++++++++++++++++++---- src/libwalletqt/Wallet.h | 23 ++++++++++++++++---- 5 files changed, 84 insertions(+), 16 deletions(-) diff --git a/components/ProcessingSplash.qml b/components/ProcessingSplash.qml index 70384f05..297631ec 100644 --- a/components/ProcessingSplash.qml +++ b/components/ProcessingSplash.qml @@ -32,13 +32,15 @@ import QtQuick.Controls 1.4 import QtQuick.Layouts 1.1 Window { - id: splash + id: root modality: Qt.ApplicationModal flags: Qt.Window | Qt.FramelessWindowHint - property alias message: message.text + property alias messageText: messageTitle.text + property alias heightProgressText : heightProgress.text + width: 200 height: 100 - opacity: 0.5 + opacity: 0.7 ColumnLayout { anchors.horizontalCenter: parent.horizontalCenter @@ -50,14 +52,23 @@ Window { } Text { - id: message + id: messageTitle text: "Please wait..." font { pointSize: 22 } horizontalAlignment: Text.AlignHCenter + Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter + } + + + Text { + id: heightProgress + font { + pointSize: 18 + } + horizontalAlignment: Text.AlignHCenter + Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter } } - - } diff --git a/main.cpp b/main.cpp index 387c4b13..129d38c2 100644 --- a/main.cpp +++ b/main.cpp @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) QObject::connect(eventFilter, SIGNAL(mousePressed(QVariant,QVariant,QVariant)), rootObject, SLOT(mousePressed(QVariant,QVariant,QVariant))); QObject::connect(eventFilter, SIGNAL(mouseReleased(QVariant,QVariant,QVariant)), rootObject, SLOT(mouseReleased(QVariant,QVariant,QVariant))); - WalletManager::instance()->setLogLevel(WalletManager::LogLevel_Max); + // WalletManager::instance()->setLogLevel(WalletManager::LogLevel_Max); return app.exec(); } diff --git a/main.qml b/main.qml index 4597e65c..85350e39 100644 --- a/main.qml +++ b/main.qml @@ -156,8 +156,12 @@ ApplicationWindow { currentWallet = wallet currentWallet.refreshed.connect(onWalletRefresh) currentWallet.updated.connect(onWalletUpdate) + currentWallet.newBlock.connect(onWalletNewBlock) + console.log("initializing with daemon address: ", persistentSettings.daemon_address) + currentWallet.initAsync(persistentSettings.daemon_address, 0); + } function walletPath() { @@ -219,6 +223,14 @@ ApplicationWindow { onWalletUpdate(); } + function onWalletNewBlock(blockHeight) { + if (splash.visible) { + var progressText = qsTr("Synchronizing blocks %1/%2").arg(blockHeight.toFixed(0)).arg(currentWallet.daemonBlockChainHeight().toFixed(0)); + console.log("Progress text: " + progressText); + splash.heightProgressText = progressText + } + } + function walletsFound() { var wallets = walletManager.findWallets(moneroAccountsDir); @@ -418,7 +430,7 @@ ApplicationWindow { height: appWindow.height / 2 x: (appWindow.width - width) / 2 + appWindow.x y: (appWindow.height - height) / 2 + appWindow.y - message: qsTr("Please wait...") + messageText: qsTr("Please wait...") } diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 034aa1de..987f4640 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -10,8 +10,7 @@ #include namespace { - - + static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 60; } class WalletListenerImpl : public Bitmonero::WalletListener @@ -39,7 +38,7 @@ public: virtual void newBlock(uint64_t height) { - qDebug() << __FUNCTION__; + // qDebug() << __FUNCTION__; emit m_wallet->newBlock(height); } @@ -137,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(); @@ -150,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) @@ -199,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 faa01263..703bd186 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -2,11 +2,11 @@ #define WALLET_H #include +#include #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, @@ -138,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; }; From ad2943fb204112ec64609b7c1e00df946664e26d Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Mon, 26 Sep 2016 22:57:45 +0300 Subject: [PATCH 3/4] libwallet_api: switched to main repo --- get_libwallet_api.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/get_libwallet_api.sh b/get_libwallet_api.sh index 0cc850ed..875ca2e9 100755 --- a/get_libwallet_api.sh +++ b/get_libwallet_api.sh @@ -1,10 +1,10 @@ #!/bin/bash -# MONERO_URL=https://github.com/monero-project/monero.git -# MONERO_BRANCH=master -MONERO_URL=https://github.com/mbg033/monero.git -MONERO_BRANCH=develop +MONERO_URL=https://github.com/monero-project/monero.git +MONERO_BRANCH=master +# MONERO_URL=https://github.com/mbg033/monero.git +# MONERO_BRANCH=develop # thanks to SO: http://stackoverflow.com/a/20283965/4118915 CPU_CORE_COUNT=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) pushd $(pwd) From f0d2e5837635b01736d0a5bceddda61c23142c2b Mon Sep 17 00:00:00 2001 From: Jacob Brydolf Date: Fri, 30 Sep 2016 12:12:26 +0200 Subject: [PATCH 4/4] make splash less resource intensive --- main.qml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.qml b/main.qml index 85350e39..0e198084 100644 --- a/main.qml +++ b/main.qml @@ -52,7 +52,7 @@ ApplicationWindow { property var currentWallet; property var transaction; property alias password : passwordDialog.password - + property int splashCounter: 0 function altKeyReleased() { ctrlPressed = false; } @@ -225,9 +225,13 @@ ApplicationWindow { function onWalletNewBlock(blockHeight) { if (splash.visible) { - var progressText = qsTr("Synchronizing blocks %1/%2").arg(blockHeight.toFixed(0)).arg(currentWallet.daemonBlockChainHeight().toFixed(0)); - console.log("Progress text: " + progressText); - splash.heightProgressText = progressText + var currHeight = blockHeight.toFixed(0) + if(currHeight > splashCounter + 1000){ + splashCounter = currHeight + var progressText = qsTr("Synchronizing blocks %1/%2").arg(currHeight).arg(currentWallet.daemonBlockChainHeight().toFixed(0)); + console.log("Progress text: " + progressText); + splash.heightProgressText = progressText + } } }