]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Ring/Transfer: cleanup
authortobtoht <tob@featherwallet.org>
Tue, 11 Mar 2025 21:51:03 +0000 (22:51 +0100)
committertobtoht <tob@featherwallet.org>
Tue, 11 Mar 2025 21:53:19 +0000 (22:53 +0100)
src/MainWindow.cpp
src/dialog/TxConfAdvDialog.cpp
src/dialog/TxInfoDialog.cpp
src/dialog/TxProofDialog.cpp
src/libwalletqt/ConstructionInfo.cpp
src/libwalletqt/ConstructionInfo.h
src/libwalletqt/Ring.h [deleted file]
src/libwalletqt/TransactionHistory.cpp
src/libwalletqt/Transfer.h
src/libwalletqt/rows/TransactionRow.cpp
src/libwalletqt/rows/TransactionRow.h

index 8ac436bcf591adcd561d93fd8fbf3c3baa5525de..cf9ca6d95734521fb2dbbe275417a471b05e7510 100644 (file)
@@ -943,7 +943,7 @@ void MainWindow::onTransactionCreated(PendingTransaction *tx, const QVector<QStr
     tx->refresh();
     QSet<QString> 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<QString> destAddresses;
     for (const auto &addr : address) {
index c4dd02ee4efb639dec2be951cb744402a2dc9bbc..b20309fad04502d043f75de1113a8a3c54a7e69e 100644 (file)
@@ -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)");
         }
index 331b957cc8baa13729c2617148d2a335788570cb..cd13f141fbe91ef814f10bc8650b0763da093c3b 100644 (file)
@@ -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;
             }
         }
index 2c0df349d386c908da98c028a81f867b55856d99..b0364076c7058fad3c3fecf7c0c60f563de95020 100644 (file)
@@ -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()) {
index e537b70582f5f79135163363a04108f6100c0941..32f767bdec5a7bb63a3d3f2f442d6f729ce74f82 100644 (file)
@@ -27,7 +27,7 @@ QList<Input *> ConstructionInfo::inputs() const {
     return m_inputs;
 }
 
-QList<Transfer *> ConstructionInfo::outputs() const {
+QList<Transfer> 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())
     {
index d5ded32fed8966d0d31ed21c4f065881bf13b894..ff18be30287e274bbc58b91a8fdf287ada407536 100644 (file)
@@ -6,9 +6,9 @@
 
 #include <QObject>
 #include <QSet>
+#include "Transfer.h"
 
 class Input;
-class Transfer;
 
 namespace Monero {
     class TransactionConstructionInfo;
@@ -24,7 +24,7 @@ public:
     QVector<QString> subaddresses() const;
     quint64 minMixinCount() const;
     QList<Input*> inputs() const;
-    QList<Transfer*> outputs() const;
+    QList<Transfer> outputs() const;
 
 private:
     explicit ConstructionInfo(const Monero::TransactionConstructionInfo *pimpl, QObject *parent = nullptr);
@@ -36,7 +36,7 @@ private:
     QVector<QString> m_subaddresses;
     quint64 m_minMixinCount;
     mutable QList<Input*> m_inputs;
-    mutable QList<Transfer*> m_outputs;
+    mutable QList<Transfer> m_outputs;
 };
 
 #endif //FEATHER_CONSTRUCTIONINFO_H
diff --git a/src/libwalletqt/Ring.h b/src/libwalletqt/Ring.h
deleted file mode 100644 (file)
index b830b01..0000000
+++ /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 <QObject>
-
-class Ring : public QObject
-{
-Q_OBJECT
-
-public:
-    explicit Ring(QString _keyImage, std::vector<uint64_t> _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<uint64_t> m_ringMembers;
-
-public:
-    QString keyImage() const { return m_keyImage; }
-    std::vector<uint64_t> ringMembers() const { return m_ringMembers; }
-};
-
-#endif //FEATHER_RINGS_H
index 14b0a468d0354a5817dd139f9ba9025b788eea95..13fd1cf70c3ec7b3943b8309086acb40a358c736 100644 (file)
@@ -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);
index b085e0391ded82f21b352bd748f3ecaa9774cc59..486054ec7ca9cf990dd956a30e128c389045aa93 100644 (file)
@@ -4,27 +4,14 @@
 #ifndef TRANSFER_H
 #define TRANSFER_H
 
-#include <QObject>
-
-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
index 6912dfb1ff64969329621556daea947303c8e0c2..65b3c74a7a631d030b7c5a88fe68b7f6d66b3475 100644 (file)
@@ -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<QString> TransactionRow::destinations() const
 {
     QList<QString> dests;
     for (auto const& t: m_transfers) {
-        dests.append(t->address());
+        dests.append(t.address);
     }
     return dests;
 }
 
-QList<Transfer*> TransactionRow::transfers() const {
+QList<Transfer> 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);
 }
index 49ce5d9017625038ca906a620f44980b495faa65..9ae6f357edb0ddd65e0a17b72efdce334a2e4577 100644 (file)
@@ -4,13 +4,21 @@
 #ifndef FEATHER_TRANSACTIONROW_H
 #define FEATHER_TRANSACTIONROW_H
 
-class Transfer;
-class Ring;
-
 #include <QObject>
 #include <QSet>
 #include <QDateTime>
 
+struct Ring
+{
+    QString keyImage;
+    std::vector<uint64_t> ringMembers;
+
+    explicit Ring(QString _keyImage, std::vector<uint64_t> _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<QString> destinations() const;
-    QList<Transfer*> transfers() const;
+    QList<Transfer> transfers() const;
     QString rings_formatted() const;
     bool hasPaymentId() const;
 
@@ -59,8 +67,8 @@ private:
 
 private:
     friend class TransactionHistory;
-    QList<Transfer*> m_transfers;
-    QList<Ring*> m_rings;
+    QList<Transfer> m_transfers;
+    QList<Ring> 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;