Use c# 8 ranges
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -399,8 +399,8 @@ namespace WalletWasabi.Backend.Controllers
int takeBlindCount = round.EstimateBestMixingLevel(alice);
- alice.BlindedOutputScripts = alice.BlindedOutputScripts.Take(takeBlindCount).ToArray();
- alice.BlindedOutputSignatures = alice.BlindedOutputSignatures.Take(takeBlindCount).ToArray();
+ alice.BlindedOutputScripts = alice.BlindedOutputScripts[..takeBlindCount];
+ alice.BlindedOutputSignatures = alice.BlindedOutputSignatures[..takeBlindCount];
resp.BlindedOutputSignatures = alice.BlindedOutputSignatures; // Do not give back more mixing levels than we'll use.
// Progress round if needed.

MODIFY
WalletWasabi/Backend/Models/FilterModel.cs
WalletWasabi/Backend/Models/FilterModel.cs
@@ -28,7 +28,7 @@ namespace WalletWasabi.Backend.Models
// https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
// The parameter k MUST be set to the first 16 bytes of the hash of the block for which the filter
// is constructed.This ensures the key is deterministic while still varying from block to block.
- public byte[] FilterKey => Header.BlockHash.ToBytes().Take(16).ToArray();
+ public byte[] FilterKey => Header.BlockHash.ToBytes()[..16];
public string ToLine()
{

MODIFY
WalletWasabi/Helpers/PasswordHelper.cs
WalletWasabi/Helpers/PasswordHelper.cs
@@ -42,7 +42,7 @@ namespace WalletWasabi.Helpers
// On OSX Avalonia gets the string from the Clipboard as byte[] and size.
// The size was mistakenly taken from the size of the original string which is not correct because of the UTF8 encoding.
byte[] bytes = Encoding.UTF8.GetBytes(text);
- var myString = Encoding.UTF8.GetString(bytes.Take(text.Length).ToArray());
+ var myString = Encoding.UTF8.GetString(bytes[..text.Length]);
return text.Substring(0, myString.Length);
}

MODIFY
WalletWasabi/TorSocks5/Models/Messages/TorSocks5Request.cs
WalletWasabi/TorSocks5/Models/Messages/TorSocks5Request.cs
@@ -64,10 +64,10 @@ namespace WalletWasabi.TorSocks5.Models.Messages
Atyp.FromByte(bytes[3]);
DstAddr = new AddrField();
- DstAddr.FromBytes(bytes.Skip(4).Take(bytes.Length - 4 - 2).ToArray());
+ DstAddr.FromBytes(bytes[4..^2]);
DstPort = new PortField();
- DstPort.FromBytes(bytes.Skip(bytes.Length - 2).ToArray());
+ DstPort.FromBytes(bytes[^2..]);
}
public override byte[] ToBytes() => ByteHelpers.Combine(new byte[] { Ver.ToByte(), Cmd.ToByte(), Rsv.ToByte(), Atyp.ToByte() }, DstAddr.ToBytes(), DstPort.ToBytes());

MODIFY
WalletWasabi/TorSocks5/Models/Messages/TorSocks5Response.cs
WalletWasabi/TorSocks5/Models/Messages/TorSocks5Response.cs
@@ -64,10 +64,10 @@ namespace WalletWasabi.TorSocks5.Models.Messages
Atyp.FromByte(bytes[3]);
BndAddr = new AddrField();
- BndAddr.FromBytes(bytes.Skip(4).Take(bytes.Length - 4 - 2).ToArray());
+ BndAddr.FromBytes(bytes[4..^2]);
BndPort = new PortField();
- BndPort.FromBytes(bytes.Skip(bytes.Length - 2).ToArray());
+ BndPort.FromBytes(bytes[^2..]);
}
public override byte[] ToBytes() => ByteHelpers.Combine(new byte[] { Ver.ToByte(), Rep.ToByte(), Rsv.ToByte(), Atyp.ToByte() }, BndAddr.ToBytes(), BndPort.ToBytes());

MODIFY
WalletWasabi/TorSocks5/Models/Messages/UsernamePasswordRequest.cs
WalletWasabi/TorSocks5/Models/Messages/UsernamePasswordRequest.cs
@@ -59,7 +59,7 @@ namespace WalletWasabi.TorSocks5.Models.Messages
ULen.FromByte(bytes[1]);
UName = new UNameField();
- UName.FromBytes(bytes.Skip(2).Take(ULen.Value).ToArray());
+ UName.FromBytes(bytes[2..(2 + ULen.Value)]);
PLen = new PLenField();
PLen.FromByte(bytes[1 + ULen.Value]);
@@ -68,7 +68,7 @@ namespace WalletWasabi.TorSocks5.Models.Messages
{
throw new FormatException($"{nameof(PLen)}.{nameof(PLen.Value)} must be {nameof(bytes)}.{nameof(bytes.Length)} - 3 + {nameof(ULen)}.{nameof(ULen.Value)} = {expectedPlenValue}. Actual: {PLen.Value}.");
}
- Passwd.FromBytes(bytes.Skip(3 + ULen.Value).ToArray());
+ Passwd.FromBytes(bytes[(3 + ULen.Value)..]);
}
public override byte[] ToBytes() => ByteHelpers.Combine(new byte[] { Ver.ToByte(), ULen.ToByte() }, UName.ToBytes(), new byte[] { PLen.ToByte() }, Passwd.ToBytes());

MODIFY
WalletWasabi/TorSocks5/TorSocks5Client.cs
WalletWasabi/TorSocks5/TorSocks5Client.cs
@@ -361,12 +361,12 @@ namespace WalletWasabi.TorSocks5
// if we could fit everything into our buffer, then return it
if (!stream.DataAvailable)
{
- return receiveBuffer.Take(receiveCount).ToArray();
+ return receiveBuffer[..receiveCount];
}
// while we have data available, start building a bytearray
var builder = new ByteArrayBuilder();
- builder.Append(receiveBuffer.Take(receiveCount).ToArray());
+ builder.Append(receiveBuffer[..receiveCount]);
while (stream.DataAvailable)
{
Array.Clear(receiveBuffer, 0, receiveBuffer.Length);
@@ -375,7 +375,7 @@ namespace WalletWasabi.TorSocks5
{
throw new ConnectionException($"Not connected to Tor SOCKS5 proxy: {TorSocks5EndPoint}.");
}
- builder.Append(receiveBuffer.Take(receiveCount).ToArray());
+ builder.Append(receiveBuffer[..receiveCount]);
}
return builder.ToArray();

Use c# 8 ranges