]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Store unconfirmed transactions in wallet cache
authortobtoht <thotbot@protonmail.com>
Sun, 4 Jul 2021 21:17:10 +0000 (23:17 +0200)
committertobtoht <thotbot@protonmail.com>
Sun, 4 Jul 2021 21:17:10 +0000 (23:17 +0200)
src/HistoryWidget.cpp
src/MainWindow.cpp
src/appcontext.cpp
src/appcontext.h
src/dialog/TxConfDialog.cpp
src/dialog/TxInfoDialog.cpp

index 41191b5b79bbaf46ee35720fccb9fd0ee4bfdb0d..e31390de763bd5029fbde9837d8a78c02b740984 100644 (file)
@@ -83,7 +83,7 @@ void HistoryWidget::showContextMenu(const QPoint &point) {
     if (!tx) return;
 
     bool unconfirmed = tx->isFailed() || tx->isPending();
-    if (m_ctx->txCache.contains(tx->hash()) && unconfirmed && tx->direction() != TransactionInfo::Direction_In) {
+    if (unconfirmed && tx->direction() != TransactionInfo::Direction_In) {
         menu.addAction(icons()->icon("info2.svg"), "Resend transaction", this, &HistoryWidget::onResendTransaction);
     }
 
index 6847887e8b2df6081bd72aec704914c59250d178..c552aa722f8fe8003c64a8966974ae205f458010 100644 (file)
@@ -909,7 +909,8 @@ void MainWindow::onViewOnBlockExplorer(const QString &txid) {
 }
 
 void MainWindow::onResendTransaction(const QString &txid) {
-    if (!m_ctx->txCache.contains(txid)) {
+    QString txHex = m_ctx->getCacheTransaction(txid);
+    if (txHex.isEmpty()) {
         QMessageBox::warning(this, "Unable to resend transaction", "Transaction was not found in transaction cache. Unable to resend.");
         return;
     }
@@ -917,7 +918,7 @@ void MainWindow::onResendTransaction(const QString &txid) {
     // Connect to a different node so chances of successful relay are higher
     m_ctx->nodes->autoConnect(true);
 
-    TxBroadcastDialog dialog{this, m_ctx, m_ctx->txCache[txid]};
+    TxBroadcastDialog dialog{this, m_ctx, txHex};
     dialog.exec();
 }
 
index bed010140d008bba29a5441f6972aa4a724acf4f..2714b1252605def0e61b5b57656db032076ecd28 100644 (file)
@@ -158,6 +158,15 @@ void AppContext::onMultiBroadcast(PendingTransaction *tx) {
     }
 }
 
+void AppContext::addCacheTransaction(const QString &txid, const QString &txHex) const {
+    this->wallet->setCacheAttribute(QString("tx:%1").arg(txid), txHex);
+}
+
+QString AppContext::getCacheTransaction(const QString &txid) const {
+    QString txHex = this->wallet->getCacheAttribute(QString("tx:%1").arg(txid));
+    return txHex;
+}
+
 // ################## Models ##################
 
 void AppContext::onPreferredFiatCurrencyChanged(const QString &symbol) {
index 62b2a69dba8ff11c09b9116155723ee6c39a4dc8..46fd215c9b62612d4056d61f09042de2029ac0d4 100644 (file)
@@ -34,7 +34,6 @@ public:
 
     NetworkType::Type networkType;
     PendingTransaction::Priority tx_priority = PendingTransaction::Priority::Priority_Low;
-    QMap<QString, QString> txCache;
 
     // libwalletqt
     bool refreshed = false;
@@ -48,6 +47,9 @@ public:
 
     void stopTimers();
 
+    void addCacheTransaction(const QString &txid, const QString &txHex) const;
+    QString getCacheTransaction(const QString &txid) const;
+
 public slots:
     void onCreateTransaction(const QString &address, quint64 amount, const QString &description, bool all);
     void onCreateTransactionMultiDest(const QVector<QString> &addresses, const QVector<quint64> &amounts, const QString &description);
index 0cef511d0da998dda98d06c33c40f11b0bb7d172..2d1c4b29ca99c6d6b6d0edf01c13e32f9c256834 100644 (file)
@@ -77,7 +77,7 @@ TxConfDialog::TxConfDialog(QSharedPointer<AppContext> ctx, PendingTransaction *t
 
     connect(ui->btn_Advanced, &QPushButton::clicked, this, &TxConfDialog::setShowAdvanced);
 
-    m_ctx->txCache[tx->txid()[0]] = tx->signedTxToHex(0);
+    m_ctx->addCacheTransaction(tx->txid()[0], tx->signedTxToHex(0)); // Todo: Iterate over all txs
     this->adjustSize();
 }
 
index f1df9888d3d38296189f99650b6f206e5cd9da4e..8abcea4f0ea91e0264ca3b15fd4f4d18eb219b43 100644 (file)
@@ -34,7 +34,7 @@ TxInfoDialog::TxInfoDialog(QSharedPointer<AppContext> ctx, TransactionInfo *txIn
 
     this->setData(txInfo);
 
-    if (m_ctx->txCache.contains(txInfo->hash()) && (txInfo->isFailed() || txInfo->isPending()) && txInfo->direction() != TransactionInfo::Direction_In) {
+    if ((txInfo->isFailed() || txInfo->isPending()) && txInfo->direction() != TransactionInfo::Direction_In) {
         connect(ui->btn_rebroadcastTx, &QPushButton::pressed, [this]{
             emit resendTranscation(m_txid);
         });