Пример #1
0
 public bool TryRelease(OutPoint utxo, [NotNullWhen(returnValue: true)] out Inmate?inmate)
 {
     lock (Lock)
     {
         if (Inmates.TryGetValue(utxo, out inmate))
         {
             Inmates.Remove(utxo);
             ChangeId = Guid.NewGuid();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Пример #2
0
    public void Punish(Inmate inmate)
    {
        lock (Lock)
        {
            var utxo = inmate.Utxo;

            // If successfully removed, then it contained it previously, so make the punishment banned and restart its time.
            Inmate inmateToPunish = inmate;
            if (Inmates.Remove(utxo))
            {
                // If it was noted before, then no matter the specified punishment, it must be banned.
                // Both the started and the last disrupted round parameters must be updated.
                inmateToPunish = new Inmate(utxo, Punishment.Banned, inmate.Started, inmate.LastDisruptedRoundId);
            }

            Inmates.Add(utxo, inmateToPunish);

            ChangeId = Guid.NewGuid();
        }
    }
Пример #3
0
        public IEnumerable <Inmate> ReleaseEligibleInmates(TimeSpan time)
        {
            lock (Lock)
            {
                var released = new List <Inmate>();

                foreach (var inmate in Inmates.Values.ToList())
                {
                    if (inmate.TimeSpent > time)
                    {
                        Inmates.Remove(inmate.Utxo);
                        released.Add(inmate);
                    }
                }

                if (released.Any())
                {
                    ChangeId = Guid.NewGuid();
                }

                return(released);
            }
        }
Пример #4
0
    public IEnumerable <Inmate> ReleaseEligibleInmates(TimeSpan normalBanPeriod, TimeSpan longBanPeriod)
    {
        lock (Lock)
        {
            var released = new List <Inmate>();

            foreach (var inmate in Inmates.Values.ToList())
            {
                var banPeriod = inmate.Punishment is Punishment.LongBanned ? longBanPeriod : normalBanPeriod;
                if (inmate.TimeSpent > banPeriod)
                {
                    Inmates.Remove(inmate.Utxo);
                    released.Add(inmate);
                }
            }

            if (released.Any())
            {
                ChangeId = Guid.NewGuid();
            }

            return(released);
        }
    }