public override Empty SetRewardListForOnePeriod(RewardsInfo input) { AssertSenderIsAdmin(); var periodBody = State.Periods[input.Period]; Assert(periodBody.RandomHash == Hash.Empty, "This period already terminated."); if (periodBody == null) { periodBody = new PeriodBody { Rewards = { input.Rewards }, SupposedDrawDate = input.SupposedDrawDate }; State.AllRewardsCount.Value = State.AllRewardsCount.Value.Add(input.Rewards.Values.Sum()); } else { var count = State.AllRewardsCount.Value; count = count.Sub(periodBody.Rewards.Values.Sum()); count = count.Add(input.Rewards.Values.Sum()); State.AllRewardsCount.Value = count; periodBody.Rewards.Clear(); periodBody.Rewards.Add(input.Rewards); periodBody.SupposedDrawDate = input.SupposedDrawDate; } State.Periods[input.Period] = periodBody; return(new Empty()); }
private void InitialNextPeriod() { var periodBody = State.Periods[State.CurrentPeriod.Value]; if (periodBody == null) { periodBody = new PeriodBody { StartId = State.SelfIncreasingIdForLottery.Value, BlockNumber = Context.CurrentHeight.Add(State.DrawingLag.Value), RandomHash = Hash.Empty }; } else { periodBody.StartId = State.SelfIncreasingIdForLottery.Value; periodBody.BlockNumber = Context.CurrentHeight.Add(State.DrawingLag.Value); periodBody.RandomHash = Hash.Empty; } State.Periods[State.CurrentPeriod.Value] = periodBody; }