예제 #1
0
        public override List <TransactionId> PerformTransactionSelection(IEventPoolProvider chainEventPoolProvider, List <TransactionId> existingTransactions)
        {
            var poolTransactions = ((INeuraliumChainPoolProviderGenerix)chainEventPoolProvider).GetTransactionIdsAndTip();

            // exclude the transactions that should not be selected
            var availableTransactions = poolTransactions.Where(p => !existingTransactions.Contains(p.transactionIds)).ToList();

            if (!availableTransactions.Any())
            {
                return(new List <TransactionId>());
            }

            // remove transactions with no tip, we so desired
            var tipAvailableTransactions   = availableTransactions.Where(t => t.tip != 0).ToList();
            var notipAvailableTransactions = availableTransactions.Where(t => t.tip == 0).ToList();

            var finalTransactions = new List <(TransactionId transactionIds, decimal tip)>();

            if (this.highestTipTransactionSelectionStrategySettings.TimeSortingMethod == HighestTipTransactionSelectionStrategySettings.TimeSortingMethods.Random)
            {
                if (this.highestTipTransactionSelectionStrategySettings.TipSortingMethod == HighestTipTransactionSelectionStrategySettings.TipSortingMethods.MostToLess)
                {
                    finalTransactions.AddRange(tipAvailableTransactions.OrderByDescending(t => t.tip));
                    finalTransactions.AddRange(notipAvailableTransactions);
                }
                else if (this.highestTipTransactionSelectionStrategySettings.TipSortingMethod == HighestTipTransactionSelectionStrategySettings.TipSortingMethods.LessToMost)
                {
                    finalTransactions.AddRange(tipAvailableTransactions.OrderBy(t => t.tip));
                    finalTransactions.AddRange(notipAvailableTransactions);
                }
                else
                {
                    finalTransactions = availableTransactions.Shuffle().ToList();
                }
            }

            if (this.highestTipTransactionSelectionStrategySettings.TimeSortingMethod != HighestTipTransactionSelectionStrategySettings.TimeSortingMethods.Random)
            {
                // lets group the times by hour (the inception is irrelevant since its all relative for grouping, so we set a dummy date)

                var group = tipAvailableTransactions.GroupBy(t => {
                    DateTime timestamp = this.timeService.GetTransactionDateTime(t.transactionIds, DateTime.Now.AddYears(-1));

                    // remove the minutes and seconds so we can group by hour
                    return(new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, timestamp.Hour, 0, 0));
                });

                if (this.highestTipTransactionSelectionStrategySettings.TimeSortingMethod == HighestTipTransactionSelectionStrategySettings.TimeSortingMethods.NewerToOlder)
                {
                    group = group.OrderByDescending(g => g.Key);
                }
                else if (this.highestTipTransactionSelectionStrategySettings.TimeSortingMethod == HighestTipTransactionSelectionStrategySettings.TimeSortingMethods.OlderToNewer)
                {
                    group = group.OrderBy(g => g.Key);
                }

                //TODO: perhaps we could make this more elaborate?

                // and now, recombine them to have our prefered order
                finalTransactions.AddRange(group.SelectMany(g => {
                    if (this.highestTipTransactionSelectionStrategySettings.TipSortingMethod == HighestTipTransactionSelectionStrategySettings.TipSortingMethods.MostToLess)
                    {
                        return(g.OrderByDescending(t => t.tip).ToList());
                    }

                    if (this.highestTipTransactionSelectionStrategySettings.TipSortingMethod == HighestTipTransactionSelectionStrategySettings.TipSortingMethods.LessToMost)
                    {
                        return(g.OrderBy(t => t.tip).ToList());
                    }

                    return(g.ToList());
                }).ToList());

                finalTransactions.AddRange(notipAvailableTransactions);
            }

            return(this.SelectSelection(finalTransactions));
        }
예제 #2
0
 protected override IElectionProcessor GetElectionProcessorV1(INeuraliumCentralCoordinator centralCoordinator, IEventPoolProvider chainEventPoolProvider)
 {
     return(new NeuraliumElectionProcessor(centralCoordinator, chainEventPoolProvider));
 }
예제 #3
0
 public NeuraliumElectionProcessor(INeuraliumCentralCoordinator centralCoordinator, IEventPoolProvider chainEventPoolProvider) : base(centralCoordinator, chainEventPoolProvider)
 {
 }