Beispiel #1
0
        protected override async Task ActionAsync(CancellationToken cancel)
        {
            var count = Prison.ReleaseEligibleInmates(Config.ReleaseUtxoFromPrisonAfter).Count();

            if (count > 0)
            {
                Logger.LogInfo($"{count} UTXOs are released from prison.");
            }

            // If something changed, send prison to file.
            if (LastKnownChange != Prison.ChangeId)
            {
                await SerializePrisonAsync().ConfigureAwait(false);

                LastKnownChange = Prison.ChangeId;
            }
        }
Beispiel #2
0
        private static Prison DeserializePrison(string prisonFilePath)
        {
            IoHelpers.EnsureContainingDirectoryExists(prisonFilePath);
            var inmates = new List <Inmate>();

            if (File.Exists(prisonFilePath))
            {
                try
                {
                    foreach (var inmate in File.ReadAllLines(prisonFilePath).Select(Inmate.FromString))
                    {
                        inmates.Add(inmate);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    Logger.LogWarning($"Deleting {prisonFilePath}");
                    File.Delete(prisonFilePath);
                }
            }

            var prison = new Prison(inmates);

            var(noted, banned) = prison.CountInmates();
            if (noted > 0)
            {
                Logger.LogInfo($"{noted} noted UTXOs are found in prison.");
            }

            if (banned > 0)
            {
                Logger.LogInfo($"{banned} banned UTXOs are found in prison.");
            }

            return(prison);
        }
Beispiel #3
0
 public async Task SerializePrisonAsync()
 {
     IoHelpers.EnsureContainingDirectoryExists(PrisonFilePath);
     await File.WriteAllLinesAsync(PrisonFilePath, Prison.GetInmates().Select(x => x.ToString())).ConfigureAwait(false);
 }