improve building the audit
MODIFY
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifierAuditArchiver.cs
WalletWasabi/WabiSabi/Backend/Banning/CoinVerifierAuditArchiver.cs
@@ -3,9 +3,11 @@ using Nito.AsyncEx;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using WalletWasabi.Extensions;
using WalletWasabi.Helpers;
namespace WalletWasabi.WabiSabi.Backend.Banning;
@@ -24,7 +26,7 @@ public class CoinVerifierAuditArchiver
public async Task SaveAuditsAsync(IEnumerable<CoinVerifyResult> results, CancellationToken cancellationToken)
{
- List<string> fileContent = new();
+ List<string> fileLines = new();
foreach (CoinVerifyResult result in results)
{
@@ -37,14 +39,40 @@ public class CoinVerifierAuditArchiver
var ids = result.ApiResponseItem?.Cscore_section.Cscore_info?.Select(x => x.Id) ?? Enumerable.Empty<int>();
var categories = result.ApiResponseItem?.Cscore_section.Cscore_info.Select(x => x.Name) ?? Enumerable.Empty<string>();
- details = $"{reportId ?? "ReportID None"}:{reportType ?? "ReportType None"}:{(!ids.Any() ? "FlagIds None" : string.Join(',', ids))}:{(!categories.Any() ? "Risk categories None" : string.Join(',', categories))}";
+ var detailsArray = new string[]
+ {
+ reportId ?? "ReportID None",
+ reportType ?? "ReportType None",
+ ids.Any() ? string.Join(' ', ids) : "FlagIds None",
+ categories.Any() ? string.Join(' ', categories) : "Risk categories None"
+ };
+
+ details = ReplaceAndJoin(':', detailsArray, '-');
}
+ else if (result.Exception is not null)
+ {
+ details = result.Exception.Message;
+ }
+
+ var auditAsArray = new string[]
+ {
+ $"{DateTimeOffset.UtcNow.ToLocalTime():yyyy-MM-dd HH:mm:ss}",
+ $"{result.Coin.Outpoint}",
+ $"{result.Coin.ScriptPubKey.GetDestinationAddress(Network.Main)}",
+ $"{result.ShouldBan}",
+ $"{result.ShouldRemove}",
+ $"{result.Coin.Amount}",
+ $"{result.Reason}",
+ $"{details}"
+ };
+
+ var audit = ReplaceAndJoin(',', auditAsArray, '-');
- fileContent.Add($"{DateTimeOffset.UtcNow.ToLocalTime():yyyy-MM-dd HH:mm:ss},{result.Coin.Outpoint},{result.Coin.ScriptPubKey.GetDestinationAddress(Network.Main)},{result.ShouldBan},{result.ShouldRemove},{result.Coin.Amount},{result.Reason},{details}");
+ fileLines.Add(audit);
}
// Sanity check: if there is nothing to write, don't append the file with an empty line.
- if (fileContent.Count <= 0)
+ if (fileLines.Count <= 0)
{
return;
}
@@ -55,7 +83,13 @@ public class CoinVerifierAuditArchiver
using (await FileAsyncLock.LockAsync(cancellationToken))
{
- await File.AppendAllLinesAsync(filePath, fileContent, cancellationToken).ConfigureAwait(false);
+ await File.AppendAllLinesAsync(filePath, fileLines, cancellationToken).ConfigureAwait(false);
+ }
}
+
+ private string ReplaceAndJoin(char separator, IEnumerable<string> textArray, char replacment)
+ {
+ var cleanTextArray = textArray.Select(x => x.Replace(separator, replacment));
+ return string.Join(separator, cleanTextArray);
}
}

improve building the audit