public AuRaRewardCalculator(AuRaParameters auRaParameters, IAbiEncoder abiEncoder, ITransactionProcessor transactionProcessor)
        {
            IList <RewardContract> BuildTransitions()
            {
                var contracts = new List <RewardContract>();

                if (auRaParameters.BlockRewardContractTransitions != null)
                {
                    contracts.AddRange(auRaParameters.BlockRewardContractTransitions.Select(t => new RewardContract(abiEncoder, t.Value, t.Key)));
                }

                contracts.Sort((a, b) => a.TransitionBlock.CompareTo(b.TransitionBlock));

                if (auRaParameters.BlockRewardContractAddress != null)
                {
                    var contractTransition = auRaParameters.BlockRewardContractTransition ?? 0;
                    if (contractTransition > (contracts.FirstOrDefault()?.TransitionBlock ?? long.MaxValue))
                    {
                        throw new ArgumentException($"{nameof(auRaParameters.BlockRewardContractTransition)} provided for {nameof(auRaParameters.BlockRewardContractAddress)} is higher than first {nameof(auRaParameters.BlockRewardContractTransitions)}.");
                    }

                    contracts.Insert(0, new RewardContract(abiEncoder, auRaParameters.BlockRewardContractAddress, contractTransition));
                }

                return(contracts);
            }

            if (auRaParameters == null)
            {
                throw new ArgumentNullException(nameof(AuRaParameters));
            }
            _transactionProcessor  = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
            _contracts             = BuildTransitions();
            _blockRewardCalculator = new StaticRewardCalculator(auRaParameters.BlockReward);
        }
Пример #2
0
        public AuRaRewardCalculator(AuRaParameters auRaParameters, IAbiEncoder abiEncoder, ITransactionProcessor transactionProcessor)
        {
            if (auRaParameters == null)
            {
                throw new ArgumentNullException(nameof(AuRaParameters));
            }
            _transactionProcessor          = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
            _blockRewardContractTransition = auRaParameters.BlockRewardContractTransition;
            if (_blockRewardContractTransition.HasValue)
            {
                _contract = new RewardContract(abiEncoder, auRaParameters.BlockRewardContractAddress);
            }

            _blockRewardCalculator = new StaticRewardCalculator(auRaParameters.BlockReward);
        }