1
mirror of https://github.com/monero-project/monero-gui synced 2024-11-25 10:47:19 +01:00

Wallet: refactor createTransaction

This commit is contained in:
xiphon 2021-01-25 11:57:49 +00:00
parent c1573c2c2a
commit 04d5fa51cf
3 changed files with 50 additions and 26 deletions

View File

@ -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

View File

@ -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<QString> &destinationAddresses,
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;
Monero::PendingTransaction * ptImpl = m_walletImpl->createTransaction(
dst_addr.toStdString(), payment_id.toStdString(), amount, mixin_count,
static_cast<Monero::PendingTransaction::Priority>(priority), currentSubaddressAccount(), subaddr_indices);
PendingTransaction * result = new PendingTransaction(ptImpl,0);
Monero::PendingTransaction *ptImpl = m_walletImpl->createTransactionMultDest(
destinations,
payment_id.toStdString(),
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;
}
void Wallet::createTransactionAsync(const QString &dst_addr, const QString &payment_id,
quint64 amount, quint32 mixin_count,
PendingTransaction::Priority priority)
void Wallet::createTransactionAsync(
const QVector<QString> &destinationAddresses,
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] {
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);
});
}

View File

@ -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<QString> &destinationAddresses,
const QString &payment_id,
const QVector<quint64> &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<QString> &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<QString> &destinationAddresses,
const QString &payment_id,
const QVector<quint64> &amounts,
quint32 mixin_count,
PendingTransaction::Priority priority);
bool disconnected() const;
bool refreshing() const;
void refreshingSet(bool value);