Fix more nullability warnings
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -275,7 +275,7 @@ namespace WalletWasabi.Backend.Controllers
var moneySoFar = Money.Zero;
for (int i = 1; i < blindedOutputCount; i++)
{
- if (!round.MixingLevels.TryGetDenomination(i, out Money denomination))
+ if (!round.MixingLevels.TryGetDenomination(i, out var denomination))
{
break;
}
@@ -434,7 +434,7 @@ namespace WalletWasabi.Backend.Controllers
return Ok("Round not found.");
}
- Alice alice = round.TryGetAliceBy(uniqueIdGuid);
+ var alice = round.TryGetAliceBy(uniqueIdGuid);
if (alice is null)
{
@@ -529,10 +529,9 @@ namespace WalletWasabi.Backend.Controllers
{
using (await OutputLock.LockAsync())
{
- Bob bob = null;
try
{
- bob = new Bob(request.OutputAddress, mixinglevel);
+ var bob = new Bob(request.OutputAddress, mixinglevel);
round.AddBob(bob);
round.AddRegisteredUnblindedSignature(request.UnblindedSignature);
}
@@ -656,7 +655,7 @@ namespace WalletWasabi.Backend.Controllers
foreach (var signaturePair in signatures)
{
int index = signaturePair.Key;
- WitScript witness = null;
+ WitScript witness;
try
{
witness = new WitScript(signaturePair.Value);
@@ -774,7 +773,7 @@ namespace WalletWasabi.Backend.Controllers
return (null, null);
}
- Alice alice = round.TryGetAliceBy(uniqueIdGuid);
+ var alice = round.TryGetAliceBy(uniqueIdGuid);
if (alice is null)
{
returnFailureResponse = NotFound("Alice not found.");

MODIFY
WalletWasabi/CoinJoin/Coordinator/Banning/UtxoReferee.cs
WalletWasabi/CoinJoin/Coordinator/Banning/UtxoReferee.cs
@@ -36,7 +36,7 @@ namespace WalletWasabi.CoinJoin.Coordinator.Banning
{
var bannedRecord = BannedUtxo.FromString(line);
- GetTxOutResponse getTxOutResponse = RpcClient.GetTxOutAsync(bannedRecord.Utxo.Hash, (int)bannedRecord.Utxo.N, includeMempool: true).GetAwaiter().GetResult();
+ var getTxOutResponse = RpcClient.GetTxOutAsync(bannedRecord.Utxo.Hash, (int)bannedRecord.Utxo.N, includeMempool: true).GetAwaiter().GetResult();
// Check if inputs are unspent.
if (getTxOutResponse is null)
@@ -91,8 +91,8 @@ namespace WalletWasabi.CoinJoin.Coordinator.Banning
var updated = false;
foreach (var utxo in toBan)
{
- BannedUtxo foundElem = null;
- if (BannedUtxos.TryGetValue(utxo, out BannedUtxo fe))
+ BannedUtxo? foundElem = null;
+ if (BannedUtxos.TryGetValue(utxo, out var fe))
{
foundElem = fe;
bool bannedForTheSameRound = foundElem.BannedForRound == bannedForRound;
@@ -121,8 +121,7 @@ namespace WalletWasabi.CoinJoin.Coordinator.Banning
var newElem = new BannedUtxo(utxo, severity, timeOfBan, isNoted, bannedForRound);
if (BannedUtxos.TryAdd(newElem.Utxo, newElem))
{
- string line = newElem.ToString();
- lines.Add(line);
+ lines.Add(newElem.ToString());
}
else
{
@@ -160,7 +159,7 @@ namespace WalletWasabi.CoinJoin.Coordinator.Banning
public async Task<BannedUtxo?> TryGetBannedAsync(OutPoint outpoint, bool notedToo)
{
- if (BannedUtxos.TryGetValue(outpoint, out BannedUtxo bannedElem))
+ if (BannedUtxos.TryGetValue(outpoint, out var bannedElem))
{
int maxBan = (int)TimeSpan.FromHours(RoundConfig.DosDurationHours).TotalMinutes;
int banLeftMinutes = maxBan - (int)bannedElem.BannedRemaining.TotalMinutes;

MODIFY
WalletWasabi/CoinJoin/Coordinator/Coordinator.cs
WalletWasabi/CoinJoin/Coordinator/Coordinator.cs
@@ -283,7 +283,7 @@ namespace WalletWasabi.CoinJoin.Coordinator
// If success save the coinjoin.
if (status == CoordinatorRoundStatus.Succeded)
{
- uint256[] mempoolHashes = null;
+ uint256[]? mempoolHashes = null;
try
{
mempoolHashes = await RpcClient.GetRawMempoolAsync().ConfigureAwait(false);

MODIFY
WalletWasabi/CoinJoin/Coordinator/Rounds/CoordinatorRound.cs
WalletWasabi/CoinJoin/Coordinator/Rounds/CoordinatorRound.cs
@@ -834,9 +834,9 @@ namespace WalletWasabi.CoinJoin.Coordinator.Rounds
// 7.2.2. Get the outputs to divide the savings between.
var indistinguishableOutputs = transaction.GetIndistinguishableOutputs(includeSingle: true).ToArray();
- int maxMixCount = indistinguishableOutputs.Max(x => x.count);
- Money bestMixAmount = indistinguishableOutputs.Where(x => x.count == maxMixCount).Max(x => x.value);
- int bestMixCount = indistinguishableOutputs.First(x => x.value == bestMixAmount).count;
+ var maxMixCount = indistinguishableOutputs.Max(x => x.count);
+ var bestMixAmount = indistinguishableOutputs.Where(x => x.count == maxMixCount).Max(x => x.value);
+ var bestMixCount = indistinguishableOutputs.First(x => x.value == bestMixAmount).count;
// 7.2.3. Get the savings per best mix outputs.
long toSavePerBestMixOutputs = toSave.Satoshi / bestMixCount;
@@ -1049,7 +1049,7 @@ namespace WalletWasabi.CoinJoin.Coordinator.Rounds
}
}
- public Alice TryGetAliceBy(Guid uniqueId)
+ public Alice? TryGetAliceBy(Guid uniqueId)
{
using (RoundSynchronizerLock.Lock())
{
@@ -1081,10 +1081,10 @@ namespace WalletWasabi.CoinJoin.Coordinator.Rounds
return; // Then no need to timeout alice.
}
- Alice alice = Alices.SingleOrDefault(x => x.UniqueId == uniqueId);
- foundAlice = alice is { };
- if (foundAlice)
+ var alice = Alices.SingleOrDefault(x => x.UniqueId == uniqueId);
+ if (alice is not null)
{
+ foundAlice = true;
alice.LastSeen = started;
}
}
@@ -1101,8 +1101,8 @@ namespace WalletWasabi.CoinJoin.Coordinator.Rounds
// 3. If the round is still running and the phase is still InputRegistration
if (Status == CoordinatorRoundStatus.Running && Phase == RoundPhase.InputRegistration)
{
- Alice alice = Alices.SingleOrDefault(x => x.UniqueId == uniqueId);
- if (alice is { })
+ var alice = Alices.SingleOrDefault(x => x.UniqueId == uniqueId);
+ if (alice is not null)
{
// 4. If LastSeen is not changed by then, remove Alice.
// But only if Alice didn't get blind sig yet.

MODIFY
WalletWasabi/Extensions/ReflectionExtensions.cs
WalletWasabi/Extensions/ReflectionExtensions.cs
@@ -8,9 +8,9 @@ namespace System.Reflection
{
Type attType = typeof(AsyncStateMachineAttribute);
- var attrib = (AsyncStateMachineAttribute)mi.GetCustomAttribute(attType);
+ var attrib = mi.GetCustomAttribute(attType) as AsyncStateMachineAttribute;
- return attrib is { };
+ return attrib is not null;
}
}
}

MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -195,17 +195,14 @@ namespace WalletWasabi.Helpers
fileExtension = fileExtension.TrimStart('.'); // Remove . if added by the caller.
- using (RegistryKey key = Registry.ClassesRoot.OpenSubKey($".{fileExtension}"))
+ using (var key = Registry.ClassesRoot.OpenSubKey($".{fileExtension}"))
{
- if (key is { })
- {
- object val = key.GetValue(null); // Read the (Default) value.
- if (val is { })
+ // Read the (Default) value.
+ if (key?.GetValue(null) is not null)
{
return true;
}
}
- }
return false;
}

MODIFY
WalletWasabi/Hwi/Parsers/HwiParser.cs
WalletWasabi/Hwi/Parsers/HwiParser.cs
@@ -307,7 +307,7 @@ namespace WalletWasabi.Hwi.Parsers
const string Prefix = "hwi";
// Order matters! https://github.com/zkSNACKs/WalletWasabi/pull/1905/commits/cecefcc50af140cc06cb93961cda86f9b21db11b
- string prefixToTrim = hwiResponse.StartsWith(WinPrefix)
+ var prefixToTrim = hwiResponse.StartsWith(WinPrefix)
? WinPrefix
: hwiResponse.StartsWith(Prefix)
? Prefix

MODIFY
WalletWasabi/Io/DigestableSafeIoManager.cs
WalletWasabi/Io/DigestableSafeIoManager.cs
@@ -105,7 +105,8 @@ namespace WalletWasabi.Io
lineTask = sr.EndOfStream ? null : sr.ReadLineAsync();
- if (linesArray[linesIndex] == line) // If the line is a line we want to write, then we know that someone else have worked into the file.
+ // If the line is a line we want to write, then we know that someone else have worked into the file.
+ if (linesArray[linesIndex] == line)
{
linesIndex++;
continue;
@@ -168,11 +169,10 @@ namespace WalletWasabi.Io
private async Task<(bool same, byte[] hash)> WorkWithHashAsync(ByteArrayBuilder byteArrayBuilder, CancellationToken cancellationToken)
{
- byte[] hash = null;
try
{
var bytes = byteArrayBuilder.ToArray();
- hash = HashHelpers.GenerateSha256Hash(bytes);
+ var hash = HashHelpers.GenerateSha256Hash(bytes);
if (File.Exists(DigestFilePath))
{
var digest = await File.ReadAllBytesAsync(DigestFilePath, cancellationToken).ConfigureAwait(false);
@@ -192,7 +192,7 @@ namespace WalletWasabi.Io
Logger.LogInfo(ex);
}
- return (false, hash);
+ return (false, Array.Empty<byte>());
}
private void ContinueBuildHash(ByteArrayBuilder byteArrayBuilder, string line)

Fix more nullability warnings