Store unconfirmed transactions in wallet cache

This commit is contained in:
tobtoht 2021-07-04 23:17:10 +02:00
parent deb0087019
commit 24811c92af
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
6 changed files with 18 additions and 6 deletions

View 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);
}

View 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();
}

View 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) {

View 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);

View 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();
}

View 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);
});