private BigInteger CalculateBonus(StoreView snapshot, BigInteger value, uint start, uint end) { if (value.IsZero || start >= end) { return(BigInteger.Zero); } if (value.Sign < 0) { throw new ArgumentOutOfRangeException(nameof(value)); } GasRecord gasRecord = snapshot.Storages[CreateStorageKey(Prefix_GasPerBlock)].GetInteroperable <GasRecord>(); BigInteger sum = 0; for (var i = gasRecord.Count - 1; i >= 0; i--) { var currentIndex = gasRecord[i].Index; if (currentIndex >= end) { continue; } if (currentIndex > start) { sum += gasRecord[i].GasPerBlock * (end - currentIndex); end = currentIndex; } else { sum += gasRecord[i].GasPerBlock * (end - start); break; } } return(value * sum * NeoHolderRewardRatio / 100 / TotalAmount); }
public static void SaveGasRecord(GasRecord record) { using (var ctx = new IotContext()) { ctx.GasRecords.Add(record); ctx.SaveChanges(); } }