mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-18 16:14:25 +01:00
upd wb
This commit is contained in:
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NBitcoin;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using WalletWasabi.WabiSabi.Client.Banning;
|
||||
@@ -17,7 +18,8 @@ public class SettingsCoinPrison : CoinPrison
|
||||
private readonly SettingsRepository _settingsRepository;
|
||||
private readonly string _coordinatorName;
|
||||
|
||||
public SettingsCoinPrison(SettingsRepository settingsRepository, string coordinatorName) : base(null)
|
||||
public SettingsCoinPrison(SettingsRepository settingsRepository, string coordinatorName,
|
||||
Dictionary<OutPoint, PrisonedCoinRecord> bannedCoins) : base(null, bannedCoins)
|
||||
{
|
||||
_settingsRepository = settingsRepository;
|
||||
_coordinatorName = coordinatorName;
|
||||
@@ -25,29 +27,30 @@ public class SettingsCoinPrison : CoinPrison
|
||||
|
||||
protected override void ToFile()
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(BannedCoins, Formatting.Indented);
|
||||
var json = JsonConvert.SerializeObject(_bannedCoins, Formatting.Indented);
|
||||
_settingsRepository.UpdateSetting(json, "wabisabi_" + _coordinatorName + "_bannedcoins").GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public static async Task<SettingsCoinPrison> CreateFromCoordinatorName(SettingsRepository settingsRepository,
|
||||
string coordinatorName, ILogger logger)
|
||||
{
|
||||
HashSet<PrisonedCoinRecord> prisonedCoinRecords = new();
|
||||
Dictionary<OutPoint, PrisonedCoinRecord> prisonedCoinRecords = new();
|
||||
try
|
||||
{
|
||||
var data = await settingsRepository.GetSettingAsync<string>("wabisabi_" + coordinatorName + "_bannedcoins");
|
||||
if (string.IsNullOrWhiteSpace(data))
|
||||
{
|
||||
logger.LogDebug("Prisoned coins file is empty.");
|
||||
return new(settingsRepository, coordinatorName);
|
||||
return new(settingsRepository, coordinatorName, new());
|
||||
}
|
||||
prisonedCoinRecords = JsonConvert.DeserializeObject<HashSet<PrisonedCoinRecord>>(data)
|
||||
prisonedCoinRecords = JsonConvert.DeserializeObject<Dictionary<OutPoint, PrisonedCoinRecord>>(data)
|
||||
?? throw new InvalidDataException("Prisoned coins file is corrupted.");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.LogError($"There was an error during loading {nameof(SettingsCoinPrison)}. Ignoring corrupt data.", exc);
|
||||
}
|
||||
return new(settingsRepository, coordinatorName){ BannedCoins = prisonedCoinRecords };
|
||||
|
||||
return new(settingsRepository, coordinatorName, prisonedCoinRecords);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user