Fix CodeFactor?
MODIFY
WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs
WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs
@@ -30,41 +30,35 @@ namespace WalletWasabi.Blockchain.Analysis
var ownInputCount = tx.WalletInputs.Count;
var ownOutputCount = tx.WalletOutputs.Count;
- var othersOutputCount = outputCount - ownOutputCount;
-
- if (inputCount == ownInputCount && outputCount == ownOutputCount)
+ if (inputCount == ownInputCount)
{
- // If self spend then retain anonset:
- // Reusing pubkey on the input side is good, the punishment happened already.
- var distinctWalletInputPubKeys = tx.WalletInputs.Select(x => x.HdPubKey).ToHashSet();
- var anonset = Intersect(distinctWalletInputPubKeys.Select(x => x.AnonymitySet), 1);
- foreach (var key in tx.WalletInputs.Concat(tx.WalletOutputs).Select(x => x.HdPubKey))
+ if (outputCount == ownOutputCount)
{
- key.AnonymitySet = anonset;
+ AnalyzeSelfSpend(tx);
}
- }
- else if (inputCount == ownInputCount && othersOutputCount > 0)
- {
- // If all our inputs are ours and there's more than one output that isn't,
- // then we can assume that the persons the money was sent to learnt our inputs.
- // AND if there're outputs that go to someone else,
- // then we can assume that the people learnt our change outputs,
- // or at the very least assume that all the changes in the tx is ours.
- // For example even if the assumed change output is a payment to someone, a blockchain analyzer
- // probably would just assume it's ours and go on with its life.
- foreach (var key in tx.WalletInputs.Concat(tx.WalletOutputs).Select(x => x.HdPubKey))
+ else
{
- key.AnonymitySet = 1;
+ AnalyzeNormalSpend(tx);
}
}
else
{
+ AnalyzeCoinjoin(tx);
+ }
+
+ AnalyzeClusters(tx);
+ }
+
+ private void AnalyzeCoinjoin(SmartTransaction tx)
+ {
+ var ownInputCount = tx.WalletInputs.Count;
var distinctWalletInputPubKeys = tx.WalletInputs.Select(x => x.HdPubKey).ToHashSet();
var inheritedAnonset = 0;
if (ownInputCount > 0)
{
// If we provided inputs to the transaction.
// Reusing pubkey on the input side is good, the punishment happened already.
+ var inputCount = tx.Transaction.Inputs.Count;
var distinctWalletInputPubKeyCount = distinctWalletInputPubKeys.Count;
var pubKeyReuseCount = ownInputCount - distinctWalletInputPubKeyCount;
var privacyBonus = Intersect(distinctWalletInputPubKeys.Select(x => x.AnonymitySet), (double)distinctWalletInputPubKeyCount / (inputCount - pubKeyReuseCount));
@@ -111,7 +105,31 @@ namespace WalletWasabi.Blockchain.Analysis
}
}
- AnalyzeClusters(tx);
+ private static void AnalyzeNormalSpend(SmartTransaction tx)
+ {
+ // If all our inputs are ours and there's more than one output that isn't,
+ // then we can assume that the persons the money was sent to learnt our inputs.
+ // AND if there're outputs that go to someone else,
+ // then we can assume that the people learnt our change outputs,
+ // or at the very least assume that all the changes in the tx is ours.
+ // For example even if the assumed change output is a payment to someone, a blockchain analyzer
+ // probably would just assume it's ours and go on with its life.
+ foreach (var key in tx.WalletInputs.Concat(tx.WalletOutputs).Select(x => x.HdPubKey))
+ {
+ key.AnonymitySet = 1;
+ }
+ }
+
+ private void AnalyzeSelfSpend(SmartTransaction tx)
+ {
+ // If self spend then retain anonset:
+ // Reusing pubkey on the input side is good, the punishment happened already.
+ var distinctWalletInputPubKeys = tx.WalletInputs.Select(x => x.HdPubKey).ToHashSet();
+ var anonset = Intersect(distinctWalletInputPubKeys.Select(x => x.AnonymitySet), 1);
+ foreach (var key in tx.WalletInputs.Concat(tx.WalletOutputs).Select(x => x.HdPubKey))
+ {
+ key.AnonymitySet = anonset;
+ }
}
private void AnalyzeClusters(SmartTransaction tx)

Fix CodeFactor?