예제 #1
0
        public async Task ExecuteAsync(
            IBalanceRepository balanceRepository,
            IBalanceMonitoringTaskRepository balanceMonitoringTaskRepository,
            ITransactionReceiptRepository transactionReceiptRepository,
            IBlockchainService blockchainService,
            BigInteger blockNumber)
        {
            var clearBlockTask = transactionReceiptRepository.ClearBlockAsync(blockNumber);

            var transactionReceipts = (await blockchainService.GetTransactionReceiptsAsync(blockNumber))
                                      .ToList();

            var affectedAddresses = transactionReceipts
                                    .Select(GetAddresses)
                                    .SelectMany(x => x)
                                    .Where(x => !string.IsNullOrEmpty(x) && x != "0x")
                                    .Distinct();

            var ownAddresses = new List <string>();

            foreach (var address in affectedAddresses)
            {
                var balance = await balanceRepository.TryGetAsync(address);

                if (balance != null)
                {
                    ownAddresses.Add(address);

                    if (balance.BlockNumber < blockNumber)
                    {
                        await balanceMonitoringTaskRepository.EnqueueAsync
                        (
                            new BalanceMonitoringTask(address)
                        );
                    }
                }
            }

            await clearBlockTask;

            if (_indexOnlyOwnTransactions)
            {
                var ownTransactionReceipts = transactionReceipts
                                             .Where(x => ownAddresses.Contains(x.From) || ownAddresses.Contains(x.To));

                foreach (var receipt in ownTransactionReceipts)
                {
                    await transactionReceiptRepository.InsertOrReplaceAsync(receipt);
                }
            }
            else
            {
                foreach (var receipt in transactionReceipts)
                {
                    await transactionReceiptRepository.InsertOrReplaceAsync(receipt);
                }
            }
        }
 public DefaultBalanceService(
     IBalanceMonitoringTaskRepository balanceMonitoringTaskRepository,
     IBalanceRepository balanceRepository,
     IBlockchainService blockchainService,
     ILogFactory logFactory)
 {
     _balanceMonitoringTaskRepository = balanceMonitoringTaskRepository;
     _balanceRepository = balanceRepository;
     _log = logFactory.CreateLog(this);
 }
 public DefaultBalanceMonitoringService(
     IBalanceMonitoringTaskRepository balanceMonitoringTaskRepository,
     IBalanceRepository balanceRepository,
     IBlockchainService blockchainService,
     IChaosKitty chaosKitty,
     ILogFactory logFactory)
 {
     _balanceMonitoringTaskRepository = balanceMonitoringTaskRepository;
     _blockchainService = blockchainService;
     _chaosKitty        = chaosKitty;
     _log = logFactory.CreateLog(this);
     _balanceRepository = balanceRepository;
 }
예제 #4
0
 public DefaultBalanceCheckSchedulingService(
     IBalanceCheckSchedulerLockRepository balanceCheckSchedulerLockRepository,
     IBalanceRepository balanceRepository,
     IBalanceMonitoringTaskRepository balanceMonitoringTaskRepository,
     IBlockchainService blockchainService,
     ILogFactory logFactory,
     Settings settings)
 {
     _balanceCheckSchedulerLockRepository = balanceCheckSchedulerLockRepository;
     _balanceRepository = balanceRepository;
     _balanceMonitoringTaskRepository = balanceMonitoringTaskRepository;
     _blockchainService = blockchainService;
     _log = logFactory.CreateLog(this);
     _maximalBalanceCheckPeriod = settings.MaximalBalanceCheckPeriod;
 }
 public DefaultBlockchainIndexingService(
     IBalanceMonitoringTaskRepository balanceMonitoringTaskRepository,
     IBalanceRepository balanceRepository,
     IBlockchainIndexationStateRepository stateRepository,
     IBlockchainService blockchainServiceService,
     IBlockIndexationLockRepository blockLockRepository,
     IChaosKitty chaosKitty,
     IIndexBlockStrategy indexBlockStrategy,
     ILogFactory logFactory,
     Settings settings,
     ITransactionReceiptRepository transactionReceiptRepository)
 {
     _balanceRepository = balanceRepository;
     _balanceMonitoringTaskRepository = balanceMonitoringTaskRepository;
     _blockchainService   = blockchainServiceService;
     _blockLockDuration   = settings.BlockLockDuration;
     _blockLockRepository = blockLockRepository;
     _chaosKitty          = chaosKitty;
     _indexBlockStrategy  = indexBlockStrategy;
     _log = logFactory.CreateLog(this);
     _minBlockNumberToIndex        = settings.MinBlockNumberToIndex;
     _stateRepository              = stateRepository;
     _transactionReceiptRepository = transactionReceiptRepository;
 }