From: tobtoht Date: Tue, 11 Mar 2025 21:51:03 +0000 (+0100) Subject: Ring/Transfer: cleanup X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=1219bfc3a7226be33605ef04f2b9f320418de92c;p=gamesguru%2Ffeather.git Ring/Transfer: cleanup --- diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 8ac436bc..cf9ca6d9 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -943,7 +943,7 @@ void MainWindow::onTransactionCreated(PendingTransaction *tx, const QVectorrefresh(); QSet outputAddresses; for (const auto &output : tx->transaction(0)->outputs()) { - outputAddresses.insert(WalletManager::baseAddressFromIntegratedAddress(output->address(), constants::networkType)); + outputAddresses.insert(WalletManager::baseAddressFromIntegratedAddress(output.address, constants::networkType)); } QSet destAddresses; for (const auto &addr : address) { diff --git a/src/dialog/TxConfAdvDialog.cpp b/src/dialog/TxConfAdvDialog.cpp index c4dd02ee..b20309fa 100644 --- a/src/dialog/TxConfAdvDialog.cpp +++ b/src/dialog/TxConfAdvDialog.cpp @@ -151,10 +151,10 @@ void TxConfAdvDialog::setupConstructionData(ConstructionInfo *ci) { for (const auto &out: ci->outputs()) { auto *item = new QTreeWidgetItem(ui->treeOutputs); - item->setText(0, out->address()); - item->setText(1, WalletManager::displayAmount(out->amount())); + item->setText(0, out.address); + item->setText(1, WalletManager::displayAmount(out.amount)); item->setFont(0, Utils::getMonospaceFont()); - auto index = m_wallet->subaddressIndex(out->address()); + auto index = m_wallet->subaddressIndex(out.address); QBrush brush; if (index.isChange()) { brush = QBrush(ColorScheme::YELLOW.asColor(true)); @@ -165,7 +165,7 @@ void TxConfAdvDialog::setupConstructionData(ConstructionInfo *ci) { brush = QBrush(ColorScheme::GREEN.asColor(true)); item->setToolTip(0, "Wallet receive address"); } - else if (out->amount() == 0) { + else if (out.amount == 0) { brush = QBrush(ColorScheme::GRAY.asColor(true)); item->setToolTip(0, "Dummy output (Min. 2 outs consensus rule)"); } diff --git a/src/dialog/TxInfoDialog.cpp b/src/dialog/TxInfoDialog.cpp index 331b957c..cd13f141 100644 --- a/src/dialog/TxInfoDialog.cpp +++ b/src/dialog/TxInfoDialog.cpp @@ -79,14 +79,14 @@ TxInfoDialog::TxInfoDialog(Wallet *wallet, TransactionRow *txInfo, QWidget *pare bool hasIntegrated = false; for (const auto& transfer : transfers) { - auto address = transfer->address(); - auto amount = WalletManager::displayAmount(transfer->amount()); + auto address = transfer.address; + auto amount = WalletManager::displayAmount(transfer.amount); auto index = m_wallet->subaddressIndex(address); - cursor.insertText(address, Utils::addressTextFormat(index, transfer->amount())); + cursor.insertText(address, Utils::addressTextFormat(index, transfer.amount)); cursor.insertText(QString(" %1").arg(amount), QTextCharFormat()); cursor.insertBlock(); - if (WalletManager::baseAddressFromIntegratedAddress(transfer->address(), constants::networkType) != transfer->address()) { + if (WalletManager::baseAddressFromIntegratedAddress(transfer.address, constants::networkType) != transfer.address) { hasIntegrated = true; } } diff --git a/src/dialog/TxProofDialog.cpp b/src/dialog/TxProofDialog.cpp index 2c0df349..b0364076 100644 --- a/src/dialog/TxProofDialog.cpp +++ b/src/dialog/TxProofDialog.cpp @@ -22,7 +22,7 @@ TxProofDialog::TxProofDialog(QWidget *parent, Wallet *wallet, TransactionRow *tx m_direction = txInfo->direction(); for (auto const &t: txInfo->transfers()) { - m_OutDestinations.push_back(t->address()); + m_OutDestinations.push_back(t.address); } for (auto const &s: txInfo->subaddrIndex()) { diff --git a/src/libwalletqt/ConstructionInfo.cpp b/src/libwalletqt/ConstructionInfo.cpp index e537b705..32f767bd 100644 --- a/src/libwalletqt/ConstructionInfo.cpp +++ b/src/libwalletqt/ConstructionInfo.cpp @@ -27,7 +27,7 @@ QList ConstructionInfo::inputs() const { return m_inputs; } -QList ConstructionInfo::outputs() const { +QList ConstructionInfo::outputs() const { return m_outputs; } @@ -44,8 +44,7 @@ ConstructionInfo::ConstructionInfo(const Monero::TransactionConstructionInfo *pi for (auto const &o : pimpl->outputs()) { - Transfer *output = new Transfer(o.amount, QString::fromStdString(o.address), this); - m_outputs.append(output); + m_outputs.emplace_back(o.amount, QString::fromStdString(o.address)); } for (uint32_t i : pimpl->subaddressIndices()) { diff --git a/src/libwalletqt/ConstructionInfo.h b/src/libwalletqt/ConstructionInfo.h index d5ded32f..ff18be30 100644 --- a/src/libwalletqt/ConstructionInfo.h +++ b/src/libwalletqt/ConstructionInfo.h @@ -6,9 +6,9 @@ #include #include +#include "Transfer.h" class Input; -class Transfer; namespace Monero { class TransactionConstructionInfo; @@ -24,7 +24,7 @@ public: QVector subaddresses() const; quint64 minMixinCount() const; QList inputs() const; - QList outputs() const; + QList outputs() const; private: explicit ConstructionInfo(const Monero::TransactionConstructionInfo *pimpl, QObject *parent = nullptr); @@ -36,7 +36,7 @@ private: QVector m_subaddresses; quint64 m_minMixinCount; mutable QList m_inputs; - mutable QList m_outputs; + mutable QList m_outputs; }; #endif //FEATHER_CONSTRUCTIONINFO_H diff --git a/src/libwalletqt/Ring.h b/src/libwalletqt/Ring.h deleted file mode 100644 index b830b015..00000000 --- a/src/libwalletqt/Ring.h +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// SPDX-FileCopyrightText: The Monero Project - -#ifndef FEATHER_RINGS_H -#define FEATHER_RINGS_H - -#include - -class Ring : public QObject -{ -Q_OBJECT - -public: - explicit Ring(QString _keyImage, std::vector _ringMembers, QObject *parent = nullptr): QObject(parent), m_keyImage(std::move(_keyImage)), m_ringMembers(std::move(_ringMembers)) {}; - -private: - friend class TransactionInfo; - QString m_keyImage; - std::vector m_ringMembers; - -public: - QString keyImage() const { return m_keyImage; } - std::vector ringMembers() const { return m_ringMembers; } -}; - -#endif //FEATHER_RINGS_H diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp index 14b0a468..13fd1cf7 100644 --- a/src/libwalletqt/TransactionHistory.cpp +++ b/src/libwalletqt/TransactionHistory.cpp @@ -8,7 +8,6 @@ #include "constants.h" #include "WalletManager.h" #include "Transfer.h" -#include "Ring.h" #include "wallet/wallet2.h" QString description(tools::wallet2 *wallet2, const tools::wallet2::payment_details &pd) @@ -178,13 +177,15 @@ void TransactionHistory::refresh() // single output transaction might contain multiple transfers for (auto const &d: pd.m_dests) { - Transfer *transfer = new Transfer(d.amount, QString::fromStdString(d.address(m_wallet2->nettype(), pd.m_payment_id, !hasFakePaymentId)), this); - t->m_transfers.append(transfer); + t->m_transfers.emplace_back( + d.amount, + QString::fromStdString(d.address(m_wallet2->nettype(), pd.m_payment_id, !hasFakePaymentId))); } for (auto const &r: pd.m_rings) { - Ring *ring = new Ring(QString::fromStdString(epee::string_tools::pod_to_hex(r.first)), cryptonote::relative_output_offsets_to_absolute(r.second), this); - t->m_rings.append(ring); + t->m_rings.emplace_back( + QString::fromStdString(epee::string_tools::pod_to_hex(r.first)), + cryptonote::relative_output_offsets_to_absolute(r.second)); } m_rows.append(t); @@ -231,13 +232,15 @@ void TransactionHistory::refresh() for (auto const &d: pd.m_dests) { - Transfer *transfer = new Transfer(d.amount, QString::fromStdString(d.address(m_wallet2->nettype(), pd.m_payment_id, !hasFakePaymentId)), this); - t->m_transfers.append(transfer); + t->m_transfers.emplace_back( + d.amount, + QString::fromStdString(d.address(m_wallet2->nettype(), pd.m_payment_id, !hasFakePaymentId))); } for (auto const &r: pd.m_rings) { - Ring *ring = new Ring(QString::fromStdString(epee::string_tools::pod_to_hex(r.first)), cryptonote::relative_output_offsets_to_absolute(r.second), this); - t->m_rings.append(ring); + t->m_rings.emplace_back( + QString::fromStdString(epee::string_tools::pod_to_hex(r.first)), + cryptonote::relative_output_offsets_to_absolute(r.second)); } m_rows.append(t); diff --git a/src/libwalletqt/Transfer.h b/src/libwalletqt/Transfer.h index b085e039..486054ec 100644 --- a/src/libwalletqt/Transfer.h +++ b/src/libwalletqt/Transfer.h @@ -4,27 +4,14 @@ #ifndef TRANSFER_H #define TRANSFER_H -#include - -class Transfer : public QObject +struct Transfer { - Q_OBJECT - -public: - explicit Transfer(uint64_t amount, QString address, QObject *parent = nullptr) - : QObject(parent) - , m_amount(amount) - , m_address(std::move(address)) {}; - - quint64 amount() const { return m_amount; } - QString address() const { return m_address; } - -private: - friend class TransactionInfo; - friend class ConstructionInfo; + QString address; + quint64 amount; - quint64 m_amount; - QString m_address; + explicit Transfer(uint64_t amount_, QString address_) + : address(std::move(address_)) + , amount(amount_) {} }; #endif // TRANSFER_H diff --git a/src/libwalletqt/rows/TransactionRow.cpp b/src/libwalletqt/rows/TransactionRow.cpp index 6912dfb1..65b3c74a 100644 --- a/src/libwalletqt/rows/TransactionRow.cpp +++ b/src/libwalletqt/rows/TransactionRow.cpp @@ -4,7 +4,6 @@ #include "TransactionRow.h" #include "WalletManager.h" #include "Transfer.h" -#include "Ring.h" TransactionRow::TransactionRow(QObject *parent) : QObject(parent) @@ -145,12 +144,12 @@ QList TransactionRow::destinations() const { QList dests; for (auto const& t: m_transfers) { - dests.append(t->address()); + dests.append(t.address); } return dests; } -QList TransactionRow::transfers() const { +QList TransactionRow::transfers() const { return m_transfers; } @@ -158,8 +157,8 @@ QString TransactionRow::rings_formatted() const { QString rings; for (auto const& r: m_rings) { - rings += r->keyImage() + ": \n"; - for (uint64_t m : r->ringMembers()){ + rings += r.keyImage + ": \n"; + for (uint64_t m : r.ringMembers){ rings += QString::number(m) + " "; } rings += "\n\n"; @@ -173,6 +172,4 @@ bool TransactionRow::hasPaymentId() const { TransactionRow::~TransactionRow() { - qDeleteAll(m_transfers); - qDeleteAll(m_rings); } diff --git a/src/libwalletqt/rows/TransactionRow.h b/src/libwalletqt/rows/TransactionRow.h index 49ce5d90..9ae6f357 100644 --- a/src/libwalletqt/rows/TransactionRow.h +++ b/src/libwalletqt/rows/TransactionRow.h @@ -4,13 +4,21 @@ #ifndef FEATHER_TRANSACTIONROW_H #define FEATHER_TRANSACTIONROW_H -class Transfer; -class Ring; - #include #include #include +struct Ring +{ + QString keyImage; + std::vector ringMembers; + + explicit Ring(QString _keyImage, std::vector _ringMembers) + : keyImage(std::move(_keyImage)) + , ringMembers(std::move(_ringMembers)) {} +}; +struct Transfer; + class TransactionRow : public QObject { Q_OBJECT @@ -50,7 +58,7 @@ public: QString time() const; QString paymentId() const; QList destinations() const; - QList transfers() const; + QList transfers() const; QString rings_formatted() const; bool hasPaymentId() const; @@ -59,8 +67,8 @@ private: private: friend class TransactionHistory; - QList m_transfers; - QList m_rings; + QList m_transfers; + QList m_rings; qint64 m_amount; // Amount that was sent (to destinations) or received, excludes tx fee qint64 m_balanceDelta; // How much the total balance was mutated as a result of this tx (includes tx fee) quint64 m_blockHeight;