Merge pull request #3315

04d5fa5 Wallet: refactor createTransaction (xiphon)
This commit is contained in:
luigi1111 2021-02-18 14:55:10 -05:00
commit 5039de8327
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
3 changed files with 50 additions and 26 deletions

View File

@ -820,7 +820,7 @@ ApplicationWindow {
return false; return false;
} }
function onTransactionCreated(pendingTransaction,address,paymentId,mixinCount){ function onTransactionCreated(pendingTransaction, addresses, paymentId, mixinCount) {
console.log("Transaction created"); console.log("Transaction created");
txConfirmationPopup.bottomText.text = ""; txConfirmationPopup.bottomText.text = "";
transaction = pendingTransaction; transaction = pendingTransaction;
@ -893,7 +893,7 @@ ApplicationWindow {
if (amount === "(all)") if (amount === "(all)")
currentWallet.createTransactionAllAsync(address, paymentId, mixinCount, priority); currentWallet.createTransactionAllAsync(address, paymentId, mixinCount, priority);
else else
currentWallet.createTransactionAsync(address, paymentId, amountxmr, mixinCount, priority); currentWallet.createTransactionAsync([address], paymentId, [amountxmr], mixinCount, priority);
} }
//Choose where to save transaction //Choose where to save transaction

View File

@ -532,25 +532,40 @@ void Wallet::pauseRefresh()
m_refreshEnabled = false; m_refreshEnabled = false;
} }
PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QString &payment_id, PendingTransaction *Wallet::createTransaction(
quint64 amount, quint32 mixin_count, const QVector<QString> &destinationAddresses,
PendingTransaction::Priority priority) const QString &payment_id,
const QVector<quint64> &amounts,
quint32 mixin_count,
PendingTransaction::Priority priority)
{ {
std::vector<std::string> destinations;
for (const auto &address : destinationAddresses) {
destinations.push_back(address.toStdString());
}
std::set<uint32_t> subaddr_indices; std::set<uint32_t> subaddr_indices;
Monero::PendingTransaction * ptImpl = m_walletImpl->createTransaction( Monero::PendingTransaction *ptImpl = m_walletImpl->createTransactionMultDest(
dst_addr.toStdString(), payment_id.toStdString(), amount, mixin_count, destinations,
static_cast<Monero::PendingTransaction::Priority>(priority), currentSubaddressAccount(), subaddr_indices); payment_id.toStdString(),
PendingTransaction * result = new PendingTransaction(ptImpl,0); std::vector<uint64_t>(amounts.begin(), amounts.end()),
mixin_count,
static_cast<Monero::PendingTransaction::Priority>(priority),
currentSubaddressAccount(),
subaddr_indices);
PendingTransaction *result = new PendingTransaction(ptImpl, 0);
return result; return result;
} }
void Wallet::createTransactionAsync(const QString &dst_addr, const QString &payment_id, void Wallet::createTransactionAsync(
quint64 amount, quint32 mixin_count, const QVector<QString> &destinationAddresses,
PendingTransaction::Priority priority) const QString &payment_id,
const QVector<quint64> &amounts,
quint32 mixin_count,
PendingTransaction::Priority priority)
{ {
m_scheduler.run([this, dst_addr, payment_id, amount, mixin_count, priority] { m_scheduler.run([this, destinationAddresses, payment_id, amounts, mixin_count, priority] {
PendingTransaction *tx = createTransaction(dst_addr, payment_id, amount, mixin_count, priority); PendingTransaction *tx = createTransaction(destinationAddresses, payment_id, amounts, mixin_count, priority);
emit transactionCreated(tx, dst_addr, payment_id, mixin_count); 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] { m_scheduler.run([this, dst_addr, payment_id, mixin_count, priority] {
PendingTransaction *tx = createTransactionAll(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] { m_scheduler.run([this] {
PendingTransaction *tx = createSweepUnmixableTransaction(); PendingTransaction *tx = createSweepUnmixableTransaction();
emit transactionCreated(tx, "", "", 0); emit transactionCreated(tx, {""}, "", 0);
}); });
} }

View File

@ -216,15 +216,13 @@ public:
Q_INVOKABLE void startRefresh(); Q_INVOKABLE void startRefresh();
Q_INVOKABLE void pauseRefresh(); 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 //! creates async transaction
Q_INVOKABLE void createTransactionAsync(const QString &dst_addr, const QString &payment_id, Q_INVOKABLE void createTransactionAsync(
quint64 amount, quint32 mixin_count, const QVector<QString> &destinationAddresses,
PendingTransaction::Priority priority); const QString &payment_id,
const QVector<quint64> &amounts,
quint32 mixin_count,
PendingTransaction::Priority priority);
//! creates transaction with all outputs //! creates transaction with all outputs
Q_INVOKABLE PendingTransaction * createTransactionAll(const QString &dst_addr, const QString &payment_id, Q_INVOKABLE PendingTransaction * createTransactionAll(const QString &dst_addr, const QString &payment_id,
@ -382,7 +380,11 @@ signals:
void deviceShowAddressShowed(); void deviceShowAddressShowed();
// emitted when transaction is created async // emitted when transaction is created async
void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount); void transactionCreated(
PendingTransaction *transaction,
const QVector<QString> &addresses,
const QString &paymentId,
quint32 mixinCount);
void connectionStatusChanged(int status) const; void connectionStatusChanged(int status) const;
void currentSubaddressAccountChanged() const; void currentSubaddressAccountChanged() const;
@ -415,6 +417,13 @@ private:
quint64 restoreHeight, quint64 restoreHeight,
const QString& proxyAddress); const QString& proxyAddress);
PendingTransaction *createTransaction(
const QVector<QString> &destinationAddresses,
const QString &payment_id,
const QVector<quint64> &amounts,
quint32 mixin_count,
PendingTransaction::Priority priority);
bool disconnected() const; bool disconnected() const;
bool refreshing() const; bool refreshing() const;
void refreshingSet(bool value); void refreshingSet(bool value);