예제 #1
0
        public async Task <bool> ExecuteAsync(
            long?startBlock, long?endBlock, CancellationToken cancellationToken)
        {
            startBlock = startBlock ?? await GetStartingBlockNumber();

            if (endBlock.HasValue && startBlock.Value > endBlock.Value)
            {
                return(false);
            }

            _log.LogInformation("Begin FillContractCacheAsync");
            await _strategy.FillContractCacheAsync().ConfigureAwait(false);


            _log.LogInformation("Begin BlockEnumeration");
            return(await new BlockEnumeration(
                       (blkNumber) => _blockProcessor.ProcessBlockAsync(blkNumber),
                       (retryNum) => _strategy.WaitForNextBlock(retryNum),
                       (retryNum) => _strategy.PauseFollowingAnError(retryNum),
                       () => _blockProcessor.GetMaxBlockNumberAsync(),
                       _strategy.MinimumBlockConfirmations,
                       _strategy.MaxRetries,
                       cancellationToken,
                       startBlock.Value,
                       endBlock
                       )
                   .ExecuteAsync().ConfigureAwait(false));
        }
예제 #2
0
        public async Task <bool> ExecuteAsync(int startBlock, int endBlock)
        {
            await Init();

            Stopwatch stopwatch = new Stopwatch();

            while (startBlock <= endBlock)
            {
                try
                {
                    stopwatch.Reset();
                    stopwatch.Start();
                    await _procesor.ProcessBlockAsync(startBlock).ConfigureAwait(false);

                    _retryNumber = 0;
                    stopwatch.Stop();
                    System.Console.WriteLine("Geçen süre : " + stopwatch.Elapsed.TotalSeconds);
                    System.Console.WriteLine("");
                    System.Console.WriteLine("---------------------------------------------");
                    System.Console.WriteLine("");
                    if (startBlock.ToString().EndsWith("0"))
                    {
                        System.Console.WriteLine(startBlock + " " + DateTime.Now.ToString("s"));
                    }


                    startBlock = startBlock + 1;
                }
                catch (Exception ex)
                {
                    if (ex.StackTrace.Contains("Only one usage of each socket address"))
                    {
                        Thread.Sleep(1000);
                        System.Console.WriteLine("SOCKET ERROR:" + startBlock + " " + DateTime.Now.ToString("s"));
                        await ExecuteAsync(startBlock, endBlock).ConfigureAwait(false);
                    }
                    else
                    {
                        if (_retryNumber != MaxRetries)
                        {
                            _retryNumber = _retryNumber + 1;
                            await ExecuteAsync(startBlock, endBlock).ConfigureAwait(false);
                        }
                        else
                        {
                            startBlock = startBlock + 1;
                            Log.Error().Exception(ex).Message("BlockNumber" + startBlock).Write();
                            System.Console.WriteLine("ERROR:" + startBlock + " " + DateTime.Now.ToString("s"));
                        }
                    }
                }
            }

            return(true);
        }
 public virtual Task ProcessBlockAsync(ulong blockNumber) => BlockProcessor.ProcessBlockAsync(blockNumber);
예제 #4
0
 public virtual Task ProcessBlockAsync(BigInteger blockNumber) => BlockProcessor.ProcessBlockAsync(blockNumber);