From 13a0409dcc9d23017eac10318dbd198f209458c5 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Sat, 12 Mar 2022 14:56:03 +0100 Subject: [PATCH] Send: verify tx outputs match destination addresses --- src/MainWindow.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index cd0d85f..2b59523 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -635,7 +635,25 @@ void MainWindow::onCreateTransactionSuccess(PendingTransaction *tx, const QVecto return; } - + // This is a weak check to see if we send to all specified destination addresses + // This is here to catch rare memory corruption errors during transaction construction + // TODO: also check that amounts match + tx->refresh(); + QSet outputAddresses; + for (const auto &output : tx->transaction(0)->outputs()) { + outputAddresses.insert(output->address()); + } + QSet destAddresses; + for (const auto &addr : address) { + destAddresses.insert(addr); + } + if (!outputAddresses.contains(destAddresses)) { + err = QString("%1 %2").arg(err, "Constructed transaction doesn't appear to send to (all) specified destination address(es). Try creating the transaction again."); + qDebug() << Q_FUNC_INFO << err; + this->displayWalletErrorMsg(err); + m_ctx->wallet->disposeTransaction(tx); + return; + } m_ctx->addCacheTransaction(tx->txid()[0], tx->signedTxToHex(0));