From 04d5fa51cf547975ea5bba1e82008aacb5df193c Mon Sep 17 00:00:00 2001 From: xiphon Date: Mon, 25 Jan 2021 11:57:49 +0000 Subject: [PATCH] Wallet: refactor createTransaction --- main.qml | 4 ++-- src/libwalletqt/Wallet.cpp | 45 +++++++++++++++++++++++++------------- src/libwalletqt/Wallet.h | 27 +++++++++++++++-------- 3 files changed, 50 insertions(+), 26 deletions(-) diff --git a/main.qml b/main.qml index f94618e6..e6fe6f93 100644 --- a/main.qml +++ b/main.qml @@ -820,7 +820,7 @@ ApplicationWindow { return false; } - function onTransactionCreated(pendingTransaction,address,paymentId,mixinCount){ + function onTransactionCreated(pendingTransaction, addresses, paymentId, mixinCount) { console.log("Transaction created"); txConfirmationPopup.bottomText.text = ""; transaction = pendingTransaction; @@ -893,7 +893,7 @@ ApplicationWindow { if (amount === "(all)") currentWallet.createTransactionAllAsync(address, paymentId, mixinCount, priority); else - currentWallet.createTransactionAsync(address, paymentId, amountxmr, mixinCount, priority); + currentWallet.createTransactionAsync([address], paymentId, [amountxmr], mixinCount, priority); } //Choose where to save transaction diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 010bb487..ae0f2367 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -532,25 +532,40 @@ void Wallet::pauseRefresh() m_refreshEnabled = false; } -PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QString &payment_id, - quint64 amount, quint32 mixin_count, - PendingTransaction::Priority priority) +PendingTransaction *Wallet::createTransaction( + const QVector &destinationAddresses, + const QString &payment_id, + const QVector &amounts, + quint32 mixin_count, + PendingTransaction::Priority priority) { + std::vector destinations; + for (const auto &address : destinationAddresses) { + destinations.push_back(address.toStdString()); + } std::set subaddr_indices; - Monero::PendingTransaction * ptImpl = m_walletImpl->createTransaction( - dst_addr.toStdString(), payment_id.toStdString(), amount, mixin_count, - static_cast(priority), currentSubaddressAccount(), subaddr_indices); - PendingTransaction * result = new PendingTransaction(ptImpl,0); + Monero::PendingTransaction *ptImpl = m_walletImpl->createTransactionMultDest( + destinations, + payment_id.toStdString(), + std::vector(amounts.begin(), amounts.end()), + mixin_count, + static_cast(priority), + currentSubaddressAccount(), + subaddr_indices); + PendingTransaction *result = new PendingTransaction(ptImpl, 0); return result; } -void Wallet::createTransactionAsync(const QString &dst_addr, const QString &payment_id, - quint64 amount, quint32 mixin_count, - PendingTransaction::Priority priority) +void Wallet::createTransactionAsync( + const QVector &destinationAddresses, + const QString &payment_id, + const QVector &amounts, + quint32 mixin_count, + PendingTransaction::Priority priority) { - m_scheduler.run([this, dst_addr, payment_id, amount, mixin_count, priority] { - PendingTransaction *tx = createTransaction(dst_addr, payment_id, amount, mixin_count, priority); - emit transactionCreated(tx, dst_addr, payment_id, mixin_count); + m_scheduler.run([this, destinationAddresses, payment_id, amounts, mixin_count, priority] { + PendingTransaction *tx = createTransaction(destinationAddresses, payment_id, amounts, mixin_count, priority); + emit transactionCreated(tx, destinationAddresses, payment_id, mixin_count); }); } @@ -571,7 +586,7 @@ void Wallet::createTransactionAllAsync(const QString &dst_addr, const QString &p { m_scheduler.run([this, dst_addr, payment_id, mixin_count, priority] { PendingTransaction *tx = createTransactionAll(dst_addr, payment_id, mixin_count, priority); - emit transactionCreated(tx, dst_addr, payment_id, mixin_count); + emit transactionCreated(tx, {dst_addr}, payment_id, mixin_count); }); } @@ -586,7 +601,7 @@ void Wallet::createSweepUnmixableTransactionAsync() { m_scheduler.run([this] { PendingTransaction *tx = createSweepUnmixableTransaction(); - emit transactionCreated(tx, "", "", 0); + emit transactionCreated(tx, {""}, "", 0); }); } diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 0f6d1353..98a47f92 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -216,15 +216,13 @@ public: Q_INVOKABLE void startRefresh(); Q_INVOKABLE void pauseRefresh(); - //! creates transaction - 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); + Q_INVOKABLE void createTransactionAsync( + const QVector &destinationAddresses, + const QString &payment_id, + const QVector &amounts, + quint32 mixin_count, + PendingTransaction::Priority priority); //! creates transaction with all outputs Q_INVOKABLE PendingTransaction * createTransactionAll(const QString &dst_addr, const QString &payment_id, @@ -382,7 +380,11 @@ signals: void deviceShowAddressShowed(); // emitted when transaction is created async - void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount); + void transactionCreated( + PendingTransaction *transaction, + const QVector &addresses, + const QString &paymentId, + quint32 mixinCount); void connectionStatusChanged(int status) const; void currentSubaddressAccountChanged() const; @@ -415,6 +417,13 @@ private: quint64 restoreHeight, const QString& proxyAddress); + PendingTransaction *createTransaction( + const QVector &destinationAddresses, + const QString &payment_id, + const QVector &amounts, + quint32 mixin_count, + PendingTransaction::Priority priority); + bool disconnected() const; bool refreshing() const; void refreshingSet(bool value);