From 747f1fb7331355e88861db58ef4b611858bbff9a Mon Sep 17 00:00:00 2001 From: Denny Avila Date: Tue, 30 May 2023 12:56:45 -0700 Subject: [PATCH] Refactored the DeniabilityDialog to use the new wallet::calculateDeniabilizaitonCycles API. --- src/qt/deniabilitydialog.cpp | 81 +----------------------------------- src/qt/deniabilitydialog.h | 1 - 2 files changed, 2 insertions(+), 80 deletions(-) diff --git a/src/qt/deniabilitydialog.cpp b/src/qt/deniabilitydialog.cpp index 955d5e53a59..82851f9df23 100644 --- a/src/qt/deniabilitydialog.cpp +++ b/src/qt/deniabilitydialog.cpp @@ -1024,84 +1024,6 @@ void DeniabilityDialog::setModel(WalletModel* model) } } -DeniabilityDialog::DeniabilizationStats DeniabilityDialog::calculateDeniabilizationStats(const COutPoint& outpoint) const -{ - Assert(m_model); - - Wallet& wallet = m_model->wallet(); - - auto tx = wallet.getTx(outpoint.hash); - if (!tx) { - return DeniabilizationStats(0, false); - } - - if (tx->IsCoinBase()) { - // this is a block reward tx, so we tag it as such - return DeniabilizationStats(0, true); - } - - // an deniabilized coin is one we sent to ourselves - // all txIn should belong to our wallet - if (tx->vin.empty()) { - return DeniabilizationStats(0, false); - } - for (const auto& txIn : tx->vin) { - if (!wallet.txinIsMine(txIn)) { - return DeniabilizationStats(0, false); - } - } - - // all txOut should belong to our wallet - Assert(outpoint.n < tx->vout.size()); - uint n = 0; - for (const auto& txOut : tx->vout) { - if (!wallet.txoutIsMine(txOut)) { - Assert(n != outpoint.n); - return DeniabilizationStats(0, false); - } - n++; - } - - uint uniqueTxOutCount = 0; - for (const auto& txOut : tx->vout) { - // check if it's a valid destination - CTxDestination txOutDestination; - if (!ExtractDestination(txOut.scriptPubKey, txOutDestination)) { - continue; - } - - // don't count outputs that match any input addresses (eg it's change output) - bool matchesInput = false; - for (const auto& txIn : tx->vin) { - auto prevTx = wallet.getTx(txIn.prevout.hash); - if (prevTx && prevTx->vout[txIn.prevout.n].scriptPubKey == txOut.scriptPubKey) { - matchesInput = true; - break; - } - } - if (matchesInput) { - continue; - } - - uniqueTxOutCount++; - } - - // we consider two or more unique outputs an "deniabilization" of the coin - uint deniabilizationCycles = uniqueTxOutCount >= 2 ? 1 : 0; - - // all txIn and txOut are from our wallet - // however if we have multiple txIn this was either an initial deniabilization of multiple UTXOs or the user manually merged deniabilized UTXOs - // in either case we don't need to recurse into parent transactions and we can return the calculated cycles - if (tx->vin.size() > 1) { - return DeniabilizationStats(deniabilizationCycles, false); - } - - const auto& txIn = tx->vin[0]; - // now recursively calculate the deniabilization cycles of the input - DeniabilizationStats inputStats = calculateDeniabilizationStats(txIn.prevout); - return DeniabilizationStats(inputStats.cycles + deniabilizationCycles, inputStats.blockReward); -}; - void DeniabilityDialog::updateCoins() { if (!m_model) { @@ -1179,7 +1101,8 @@ void DeniabilityDialog::updateCoins() // skip spent outputs if (output.walletTxOut.is_spent) continue; - output.deniabilizationStats = calculateDeniabilizationStats(output.outpoint); + auto result = wallet.calculateDeniabilizationCycles(output.outpoint); + output.deniabilizationStats = DeniabilizationStats(result.first, result.second); coin.utxos.push_back(std::move(output)); } // skip any addresses with no unspent outputs diff --git a/src/qt/deniabilitydialog.h b/src/qt/deniabilitydialog.h index 0d3bbe721cc..4a101f84e12 100644 --- a/src/qt/deniabilitydialog.h +++ b/src/qt/deniabilitydialog.h @@ -164,7 +164,6 @@ public Q_SLOTS: void updateStart(); void updateStatus(); void updateCoinTable(); - DeniabilizationStats calculateDeniabilizationStats(const COutPoint& outpoint) const; bool signExternalSigner(interfaces::Wallet& wallet, CTransactionRef& tx, const QString& message); void finalizeTxBroadcast(uint256 hash, CAmount txFee);