@@ -1024,84 +1024,6 @@ void DeniabilityDialog::setModel(WalletModel* model)
10241024 }
10251025}
10261026
1027- DeniabilityDialog::DeniabilizationStats DeniabilityDialog::calculateDeniabilizationStats (const COutPoint& outpoint) const
1028- {
1029- Assert (m_model);
1030-
1031- Wallet& wallet = m_model->wallet ();
1032-
1033- auto tx = wallet.getTx (outpoint.hash );
1034- if (!tx) {
1035- return DeniabilizationStats (0 , false );
1036- }
1037-
1038- if (tx->IsCoinBase ()) {
1039- // this is a block reward tx, so we tag it as such
1040- return DeniabilizationStats (0 , true );
1041- }
1042-
1043- // an deniabilized coin is one we sent to ourselves
1044- // all txIn should belong to our wallet
1045- if (tx->vin .empty ()) {
1046- return DeniabilizationStats (0 , false );
1047- }
1048- for (const auto & txIn : tx->vin ) {
1049- if (!wallet.txinIsMine (txIn)) {
1050- return DeniabilizationStats (0 , false );
1051- }
1052- }
1053-
1054- // all txOut should belong to our wallet
1055- Assert (outpoint.n < tx->vout .size ());
1056- uint n = 0 ;
1057- for (const auto & txOut : tx->vout ) {
1058- if (!wallet.txoutIsMine (txOut)) {
1059- Assert (n != outpoint.n );
1060- return DeniabilizationStats (0 , false );
1061- }
1062- n++;
1063- }
1064-
1065- uint uniqueTxOutCount = 0 ;
1066- for (const auto & txOut : tx->vout ) {
1067- // check if it's a valid destination
1068- CTxDestination txOutDestination;
1069- if (!ExtractDestination (txOut.scriptPubKey , txOutDestination)) {
1070- continue ;
1071- }
1072-
1073- // don't count outputs that match any input addresses (eg it's change output)
1074- bool matchesInput = false ;
1075- for (const auto & txIn : tx->vin ) {
1076- auto prevTx = wallet.getTx (txIn.prevout .hash );
1077- if (prevTx && prevTx->vout [txIn.prevout .n ].scriptPubKey == txOut.scriptPubKey ) {
1078- matchesInput = true ;
1079- break ;
1080- }
1081- }
1082- if (matchesInput) {
1083- continue ;
1084- }
1085-
1086- uniqueTxOutCount++;
1087- }
1088-
1089- // we consider two or more unique outputs an "deniabilization" of the coin
1090- uint deniabilizationCycles = uniqueTxOutCount >= 2 ? 1 : 0 ;
1091-
1092- // all txIn and txOut are from our wallet
1093- // however if we have multiple txIn this was either an initial deniabilization of multiple UTXOs or the user manually merged deniabilized UTXOs
1094- // in either case we don't need to recurse into parent transactions and we can return the calculated cycles
1095- if (tx->vin .size () > 1 ) {
1096- return DeniabilizationStats (deniabilizationCycles, false );
1097- }
1098-
1099- const auto & txIn = tx->vin [0 ];
1100- // now recursively calculate the deniabilization cycles of the input
1101- DeniabilizationStats inputStats = calculateDeniabilizationStats (txIn.prevout );
1102- return DeniabilizationStats (inputStats.cycles + deniabilizationCycles, inputStats.blockReward );
1103- };
1104-
11051027void DeniabilityDialog::updateCoins ()
11061028{
11071029 if (!m_model) {
@@ -1179,7 +1101,8 @@ void DeniabilityDialog::updateCoins()
11791101 // skip spent outputs
11801102 if (output.walletTxOut .is_spent )
11811103 continue ;
1182- output.deniabilizationStats = calculateDeniabilizationStats (output.outpoint );
1104+ auto result = wallet.calculateDeniabilizationCycles (output.outpoint );
1105+ output.deniabilizationStats = DeniabilizationStats (result.first , result.second );
11831106 coin.utxos .push_back (std::move (output));
11841107 }
11851108 // skip any addresses with no unspent outputs
0 commit comments