From 2143392b84e089319decee65e63c2376e6fdffd4 Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Tue, 8 Nov 2016 20:23:50 +0000 Subject: [PATCH 1/3] Add a button to sweep unmixable outputs --- MiddlePanel.qml | 5 +++++ main.qml | 40 ++++++++++++++++++++++++++++++++++++++ pages/Transfer.qml | 21 ++++++++++++++++++++ src/libwalletqt/Wallet.cpp | 8 ++++++-- src/libwalletqt/Wallet.h | 5 +++++ 5 files changed, 77 insertions(+), 2 deletions(-) diff --git a/MiddlePanel.qml b/MiddlePanel.qml index 7080e338..74c731c8 100644 --- a/MiddlePanel.qml +++ b/MiddlePanel.qml @@ -52,6 +52,7 @@ Rectangle { signal paymentClicked(string address, string paymentId, string amount, int mixinCount, int priority, string description) + signal sweepUnmixableClicked() signal generatePaymentIdInvoked() signal checkPaymentClicked(string address, string txid, string txkey); @@ -308,5 +309,9 @@ Rectangle { console.log("MiddlePanel: paymentClicked") paymentClicked(address, paymentId, amount, mixinCount, priority, description) } + onSweepUnmixableClicked : { + console.log("MiddlePanel: sweepUnmixableClicked") + sweepUnmixableClicked() + } } } diff --git a/main.qml b/main.qml index 1114a56e..cf355aab 100644 --- a/main.qml +++ b/main.qml @@ -157,6 +157,7 @@ ApplicationWindow { middlePanel.checkPaymentClicked.disconnect(handleCheckPayment); } middlePanel.paymentClicked.connect(handlePayment); + middlePanel.sweepUnmixableClicked.connect(handleSweepUnmixable); // basicPanel.paymentClicked.connect(handlePayment); middlePanel.checkPaymentClicked.connect(handleCheckPayment); @@ -451,6 +452,45 @@ ApplicationWindow { currentWallet.createTransactionAsync(address, paymentId, amountxmr, mixinCount, priority); } + function handleSweepUnmixable() { + console.log("Creating transaction: ") + + transaction = currentWallet.createSweepUnmixableTransaction(); + if (transaction.status !== PendingTransaction.Status_Ok) { + console.error("Can't create transaction: ", transaction.errorString); + informationPopup.title = qsTr("Error") + translationManager.emptyString; + informationPopup.text = qsTr("Can't create transaction: ") + transaction.errorString + informationPopup.icon = StandardIcon.Critical + informationPopup.onCloseCallback = null + informationPopup.open(); + // deleting transaction object, we don't want memleaks + currentWallet.disposeTransaction(transaction); + + } else if (transaction.txCount == 0) { + informationPopup.title = qsTr("No unmixable outputs to sweep") + translationManager.emptyString + informationPopup.text = qsTr("No unmixable outputs to sweep") + translationManager.emptyString + informationPopup.icon = StandardIcon.Information + informationPopup.onCloseCallback = null + informationPopup.open() + // deleting transaction object, we don't want memleaks + currentWallet.disposeTransaction(transaction); + } else { + console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount) + + ", fee: " + walletManager.displayAmount(transaction.fee)); + + // here we show confirmation popup; + + transactionConfirmationPopup.title = qsTr("Confirmation") + translationManager.emptyString + transactionConfirmationPopup.text = qsTr("Please confirm transaction:\n") + + qsTr("\n\nAmount: ") + walletManager.displayAmount(transaction.amount) + + qsTr("\nFee: ") + walletManager.displayAmount(transaction.fee) + + translationManager.emptyString + transactionConfirmationPopup.icon = StandardIcon.Question + transactionConfirmationPopup.open() + // committing transaction + } + } + // called after user confirms transaction function handleTransactionConfirmed() { // grab transaction.txid before commit, since it clears it. diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 95c3e993..260f4b54 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -35,6 +35,7 @@ Rectangle { id: root signal paymentClicked(string address, string paymentId, string amount, int mixinCount, int priority, string description) + signal sweepUnmixableClicked() color: "#F0EEEE" @@ -295,4 +296,24 @@ Rectangle { } } + + StandardButton { + id: sweepUnmixableButton + anchors.right: parent.right + anchors.top: descriptionLine.bottom + anchors.rightMargin: 17 + anchors.topMargin: 17 + width: 60*2 + text: qsTr("SWEEP UNMIXABLE") + translationManager.emptyString + shadowReleasedColor: "#FF4304" + shadowPressedColor: "#B32D00" + releasedColor: "#FF6C3C" + pressedColor: "#FF4304" + enabled : true + onClicked: { + console.log("Transfer: sweepUnmixableClicked") + root.sweepUnmixableClicked() + + } + } } diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 78cb6949..d7fefbf9 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -216,7 +216,6 @@ PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QSt return result; } - void Wallet::createTransactionAsync(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, PendingTransaction::Priority priority) @@ -233,7 +232,12 @@ void Wallet::createTransactionAsync(const QString &dst_addr, const QString &paym }); } - +PendingTransaction *Wallet::createSweepUnmixableTransaction() +{ + Bitmonero::PendingTransaction * ptImpl = m_walletImpl->createSweepUnmixableTransaction(); + PendingTransaction * result = new PendingTransaction(ptImpl, this); + return result; +} void Wallet::disposeTransaction(PendingTransaction *t) { diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index fc7363e8..ecdfa2fd 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -130,6 +130,11 @@ public: Q_INVOKABLE void createTransactionAsync(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, PendingTransaction::Priority priority); + + // + //! creates sweep unmixable transaction + Q_INVOKABLE PendingTransaction * createSweepUnmixableTransaction(); + //! deletes transaction and frees memory Q_INVOKABLE void disposeTransaction(PendingTransaction * t); From c779b376fc06c1912b896549b5f39c4a6ef0ec5a Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Wed, 9 Nov 2016 13:00:43 +0000 Subject: [PATCH 2/3] Support for sweeping all outputs --- main.qml | 51 +++++++++++++++++++++----------------- pages/Transfer.qml | 17 ++++++++++++- src/libwalletqt/Wallet.cpp | 10 ++++++++ src/libwalletqt/Wallet.h | 6 ++++- 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/main.qml b/main.qml index cf355aab..2a8dc0df 100644 --- a/main.qml +++ b/main.qml @@ -423,33 +423,38 @@ ApplicationWindow { transactionDescription = description; // validate amount; - var amountxmr = walletManager.amountFromString(amount); - console.log("integer amount: ", amountxmr); - console.log("integer unlocked",currentWallet.unlockedBalance) - if (amountxmr <= 0) { - informationPopup.title = qsTr("Error") + translationManager.emptyString; - informationPopup.text = qsTr("Amount is wrong: expected number from %1 to %2") - .arg(walletManager.displayAmount(0)) - .arg(walletManager.maximumAllowedAmountAsSting()) - + translationManager.emptyString + if (amount !== "(all)") { + var amountxmr = walletManager.amountFromString(amount); + console.log("integer amount: ", amountxmr); + console.log("integer unlocked",currentWallet.unlockedBalance) + if (amountxmr <= 0) { + informationPopup.title = qsTr("Error") + translationManager.emptyString; + informationPopup.text = qsTr("Amount is wrong: expected number from %1 to %2") + .arg(walletManager.displayAmount(0)) + .arg(walletManager.maximumAllowedAmountAsSting()) + + translationManager.emptyString - informationPopup.icon = StandardIcon.Critical - informationPopup.onCloseCallback = null - informationPopup.open() - return; - } else if (amountxmr > currentWallet.unlockedBalance) { - informationPopup.title = qsTr("Error") + translationManager.emptyString; - informationPopup.text = qsTr("insufficient funds. Unlocked balance: %1") - .arg(walletManager.displayAmount(currentWallet.unlockedBalance)) - + translationManager.emptyString + informationPopup.icon = StandardIcon.Critical + informationPopup.onCloseCallback = null + informationPopup.open() + return; + } else if (amountxmr > currentWallet.unlockedBalance) { + informationPopup.title = qsTr("Error") + translationManager.emptyString; + informationPopup.text = qsTr("insufficient funds. Unlocked balance: %1") + .arg(walletManager.displayAmount(currentWallet.unlockedBalance)) + + translationManager.emptyString - informationPopup.icon = StandardIcon.Critical - informationPopup.onCloseCallback = null - informationPopup.open() - return; + informationPopup.icon = StandardIcon.Critical + informationPopup.onCloseCallback = null + informationPopup.open() + return; + } } - currentWallet.createTransactionAsync(address, paymentId, amountxmr, mixinCount, priority); + if (amount === "(all)") + currentWallet.createTransactionAllAsync(address, paymentId, amountxmr, mixinCount, priority); + else + currentWallet.createTransactionAsync(address, paymentId, amountxmr, mixinCount, priority); } function handleSweepUnmixable() { diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 260f4b54..3c687ff1 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -89,7 +89,7 @@ Rectangle { LineEdit { id: amountLine placeholderText: qsTr("") + translationManager.emptyString - width: parent.width - 37 - 17 + width: parent.width - 37 - 17 - 60 validator: DoubleValidator { bottom: 0.0 top: 18446744.073709551615 @@ -98,6 +98,21 @@ Rectangle { locale: "C" } } + + StandardButton { + id: amountAllButton + //anchors.left: amountLine.right + //anchors.top: amountLine.top + //anchors.bottom: amountLine.bottom + width: 60 + text: qsTr("or ALL") + translationManager.emptyString + shadowReleasedColor: "#FF4304" + shadowPressedColor: "#B32D00" + releasedColor: "#FF6C3C" + pressedColor: "#FF4304" + enabled : true + onClicked: amountLine.text = "(all)" + } } ListModel { diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index d7fefbf9..9f15bb06 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -232,6 +232,16 @@ void Wallet::createTransactionAsync(const QString &dst_addr, const QString &paym }); } +PendingTransaction *Wallet::createTransactionAll(const QString &dst_addr, const QString &payment_id, + quint32 mixin_count, PendingTransaction::Priority priority) +{ + Bitmonero::PendingTransaction * ptImpl = m_walletImpl->createTransaction( + dst_addr.toStdString(), payment_id.toStdString(), Bitmonero::optional(), mixin_count, + static_cast(priority)); + PendingTransaction * result = new PendingTransaction(ptImpl, this); + return result; +} + PendingTransaction *Wallet::createSweepUnmixableTransaction() { Bitmonero::PendingTransaction * ptImpl = m_walletImpl->createSweepUnmixableTransaction(); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index ecdfa2fd..65d955ba 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -126,12 +126,16 @@ public: Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, PendingTransaction::Priority priority); + //! creates async transaction Q_INVOKABLE void createTransactionAsync(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, PendingTransaction::Priority priority); - // + //! creates transaction with all outputs + Q_INVOKABLE PendingTransaction * createTransactionAll(const QString &dst_addr, const QString &payment_id, + quint32 mixin_count, PendingTransaction::Priority priority); + //! creates sweep unmixable transaction Q_INVOKABLE PendingTransaction * createSweepUnmixableTransaction(); From 111248f410da5133bb6c8051b674536fb4ca121f Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Fri, 11 Nov 2016 21:54:17 +0000 Subject: [PATCH 3/3] Make the new sweep functions use async transactions --- main.qml | 14 +++++++++++--- src/libwalletqt/Wallet.cpp | 29 +++++++++++++++++++++++++++++ src/libwalletqt/Wallet.h | 7 +++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/main.qml b/main.qml index 2a8dc0df..2e8d432c 100644 --- a/main.qml +++ b/main.qml @@ -386,6 +386,14 @@ ApplicationWindow { // deleting transaction object, we don't want memleaks currentWallet.disposeTransaction(transaction); + } else if (transaction.txCount == 0) { + informationPopup.title = qsTr("No unmixable outputs to sweep") + translationManager.emptyString + informationPopup.text = qsTr("No unmixable outputs to sweep") + translationManager.emptyString + informationPopup.icon = StandardIcon.Information + informationPopup.onCloseCallback = null + informationPopup.open() + // deleting transaction object, we don't want memleaks + currentWallet.disposeTransaction(transaction); } else { console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount) + ", fee: " + walletManager.displayAmount(transaction.fee)); @@ -394,13 +402,13 @@ ApplicationWindow { transactionConfirmationPopup.title = qsTr("Confirmation") + translationManager.emptyString transactionConfirmationPopup.text = qsTr("Please confirm transaction:\n") - + qsTr("\nAddress: ") + address - + qsTr("\nPayment ID: ") + paymentId + + (address === "" ? "" : (qsTr("\nAddress: ") + address)) + + (paymentId === "" ? "" : (qsTr("\nPayment ID: ") + paymentId)) + qsTr("\n\nAmount: ") + walletManager.displayAmount(transaction.amount) + qsTr("\nFee: ") + walletManager.displayAmount(transaction.fee) + qsTr("\n\nMixin: ") + mixinCount + qsTr("\n\Number of transactions: ") + transaction.txCount - + qsTr("\n\nDescription: ") + transactionDescription + + (transactionDescription === "" ? "" : (qsTr("\n\nDescription: ") + transactionDescription)) + translationManager.emptyString transactionConfirmationPopup.icon = StandardIcon.Question transactionConfirmationPopup.open() diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 9f15bb06..5f3cd5f3 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -242,6 +242,22 @@ PendingTransaction *Wallet::createTransactionAll(const QString &dst_addr, const return result; } +void Wallet::createTransactionAllAsync(const QString &dst_addr, const QString &payment_id, + quint32 mixin_count, + PendingTransaction::Priority priority) +{ + QFuture future = QtConcurrent::run(this, &Wallet::createTransactionAll, + dst_addr, payment_id, mixin_count, priority); + QFutureWatcher * watcher = new QFutureWatcher(); + watcher->setFuture(future); + connect(watcher, &QFutureWatcher::finished, + this, [this, watcher,dst_addr,payment_id,mixin_count]() { + QFuture future = watcher->future(); + watcher->deleteLater(); + emit transactionCreated(future.result(),dst_addr,payment_id,mixin_count); + }); +} + PendingTransaction *Wallet::createSweepUnmixableTransaction() { Bitmonero::PendingTransaction * ptImpl = m_walletImpl->createSweepUnmixableTransaction(); @@ -249,6 +265,19 @@ PendingTransaction *Wallet::createSweepUnmixableTransaction() return result; } +void Wallet::createSweepUnmixableTransactionAsync() +{ + QFuture future = QtConcurrent::run(this, &Wallet::createSweepUnmixableTransaction); + QFutureWatcher * watcher = new QFutureWatcher(); + watcher->setFuture(future); + connect(watcher, &QFutureWatcher::finished, + this, [this, watcher]() { + QFuture future = watcher->future(); + watcher->deleteLater(); + emit transactionCreated(future.result(),"","",0); + }); +} + void Wallet::disposeTransaction(PendingTransaction *t) { m_walletImpl->disposeTransaction(t->m_pimpl); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 65d955ba..14308ce5 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -136,9 +136,16 @@ public: Q_INVOKABLE PendingTransaction * createTransactionAll(const QString &dst_addr, const QString &payment_id, quint32 mixin_count, PendingTransaction::Priority priority); + //! creates async transaction with all outputs + Q_INVOKABLE void createTransactionAllAsync(const QString &dst_addr, const QString &payment_id, + quint32 mixin_count, PendingTransaction::Priority priority); + //! creates sweep unmixable transaction Q_INVOKABLE PendingTransaction * createSweepUnmixableTransaction(); + //! creates async sweep unmixable transaction + Q_INVOKABLE void createSweepUnmixableTransactionAsync(); + //! deletes transaction and frees memory Q_INVOKABLE void disposeTransaction(PendingTransaction * t);