Beispiel #1
0
        public RepositoryHandlerContext(IBlockchainStoreRepositoryFactory repositoryFactory)
        {
            BlockRepository              = repositoryFactory.CreateBlockRepository();
            ContractRepository           = repositoryFactory.CreateContractRepository();
            TransactionRepository        = repositoryFactory.CreateTransactionRepository();
            AddressTransactionRepository = repositoryFactory.CreateAddressTransactionRepository();
            TransactionLogRepository     = repositoryFactory.CreateTransactionLogRepository();
            TransactionVmStackRepository = repositoryFactory.CreateTransactionVmStackRepository();

            _repositories.Add(BlockRepository);
            _repositories.Add(ContractRepository);
            _repositories.Add(TransactionLogRepository);
            _repositories.Add(AddressTransactionRepository);
            _repositories.Add(TransactionLogRepository);
            _repositories.Add(TransactionVmStackRepository);

            Handlers = new HandlerContainer
            {
                BlockHandler              = new BlockRepositoryHandler(BlockRepository),
                ContractHandler           = new ContractRepositoryHandler(ContractRepository),
                TransactionHandler        = new TransactionRepositoryHandler(TransactionRepository),
                TransactionLogHandler     = new TransactionLogRepositoryHandler(TransactionLogRepository),
                TransactionVmStackHandler = new TransactionVMStackRepositoryHandler(TransactionVmStackRepository)
            };
        }
Beispiel #2
0
 public BlockStorageProcessingSteps(IBlockchainStoreRepositoryFactory repositoryFactory)
 {
     AddBlockStepStorageHandler(repositoryFactory);
     AddContractCreationStepStorageHandler(repositoryFactory);
     AddTransactionReceiptStepStorageHandler(repositoryFactory);
     AddFilterLogStepStorageHandler(repositoryFactory);
 }
 public BlockchainProcessor CreateBlockStorageProcessor(
     IBlockchainStoreRepositoryFactory blockchainStorageFactory,
     uint minimumBlockConfirmations,
     Action <BlockProcessingSteps> configureSteps = null,
     ILog log = null) => CreateBlockStorageProcessor(
     blockchainStorageFactory,
     null,
     minimumBlockConfirmations,
     configureSteps,
     log);
        public static async Task <int> Execute(
            IBlockchainStoreRepositoryFactory repositoryFactory,
            BlockchainSourceConfiguration configuration,
            FilterContainer filterContainer = null,
            bool useGeth = false,
            ILog log     = null)
        {
            IWeb3 web3 =
                useGeth
                    ? new Web3Geth(configuration.BlockchainUrl)
                    : new Web3.Web3(configuration.BlockchainUrl);

            using (var repositoryHandlerContext = new RepositoryHandlerContext(repositoryFactory))
            {
                var blockProcessor = BlockProcessorFactory
                                     .Create(
                    web3,
                    repositoryHandlerContext.Handlers,
                    filters: filterContainer,
                    postVm: configuration.PostVm,
                    processTransactionsInParallel: configuration.ProcessBlockTransactionsInParallel);

                var storageProcessingStrategy = new StorageProcessingStrategy(
                    repositoryHandlerContext, blockProcessor)
                {
                    MinimumBlockNumber        = configuration.MinimumBlockNumber ?? 0,
                    MinimumBlockConfirmations = configuration.MinimumBlockConfirmations ?? 0
                };

                var blockchainProcessor = new BlockchainProcessor(storageProcessingStrategy, log);

                var stopWatch = Stopwatch.StartNew();

                var result = await blockchainProcessor.ExecuteAsync(configuration.FromBlock, configuration.ToBlock)
                             .ConfigureAwait(false);

                System.Console.WriteLine("Duration: " + stopWatch.Elapsed);

                Debug.WriteLine($"Finished With Success: {result}");
                System.Console.WriteLine("Finished. Success:" + result);
                System.Console.ReadLine();

                return(result ? 0 : 1);
            }
        }
Beispiel #5
0
        public static async Task <int> Execute(
            IBlockchainStoreRepositoryFactory repositoryFactory,
            BlockchainSourceConfiguration configuration,
            FilterContainer filterContainer = null,
            bool useGeth = false)
        {
            IWeb3Wrapper web3 = new Web3Wrapper(
                useGeth
                    ? new Web3Geth(configuration.BlockchainUrl)
                    : new Web3.Web3(configuration.BlockchainUrl));

            using (_strategy = new PersistenceStrategy(
                       repositoryFactory, filterContainer, minimumBlockNumber: configuration.MinimumBlockNumber ?? 0))
            {
                var blockProcessor = new BlockProcessorFactory()
                                     .Create(
                    web3,
                    _strategy,
                    configuration.PostVm,
                    configuration.ProcessBlockTransactionsInParallel);

                var blockchainProcessor = new BlockchainProcessor(_strategy, blockProcessor);

                //this should not really be necessary
                //but without it, when the process is killed early, some csv records where not being flushed
                AppDomain.CurrentDomain.ProcessExit += (s, e) =>
                {
                    _strategy?.Dispose();
                };

                var stopWatch = Stopwatch.StartNew();

                var result = await blockchainProcessor.ExecuteAsync(configuration.FromBlock, configuration.ToBlock)
                             .ConfigureAwait(false);

                System.Console.WriteLine("Duration: " + stopWatch.Elapsed);

                Debug.WriteLine($"Finished With Success: {result}");
                System.Console.WriteLine("Finished. Success:" + result);
                System.Console.ReadLine();

                return(result ? 0 : 1);
            }
        }
        public BlockchainProcessor CreateBlockStorageProcessor(
            IBlockchainStoreRepositoryFactory blockchainStorageFactory,
            IBlockProgressRepository blockProgressRepository,
            uint minimumBlockConfirmations,
            Action <BlockProcessingSteps> configureSteps = null,
            ILog log = null)
        {
            var processingSteps = new BlockStorageProcessingSteps(blockchainStorageFactory);
            var orchestrator    = new BlockCrawlOrchestrator(_ethApiContractService, processingSteps);

            if (blockProgressRepository == null && blockchainStorageFactory is IBlockProgressRepositoryFactory progressRepoFactory)
            {
                blockProgressRepository = progressRepoFactory.CreateBlockProgressRepository();
            }

            blockProgressRepository = blockProgressRepository ?? new InMemoryBlockchainProgressRepository();
            var lastConfirmedBlockNumberService = new LastConfirmedBlockNumberService(_ethApiContractService.Blocks.GetBlockNumber, minimumBlockConfirmations);

            configureSteps?.Invoke(processingSteps);

            return(new BlockchainProcessor(orchestrator, blockProgressRepository, lastConfirmedBlockNumberService, log));
        }
        public PersistenceStrategy(
            IBlockchainStoreRepositoryFactory repositoryFactory,
            FilterContainer filters,
            IWaitStrategy waitStrategy    = null,
            int maxRetries                = 3,
            long minimumBlockNumber       = 0,
            int minimumBlockConfirmations = 6)
        {
            MinimumBlockNumber        = minimumBlockNumber;
            MaxRetries                = maxRetries;
            MinimumBlockConfirmations = minimumBlockConfirmations;
            Filters             = filters;
            _waitStrategy       = waitStrategy ?? new WaitStrategy();
            _blockRepository    = repositoryFactory.CreateBlockRepository();
            _contractRepository = repositoryFactory.CreateContractRepository();

            var transactionRepository        = repositoryFactory.CreateTransactionRepository();
            var addressTransactionRepository = repositoryFactory.CreateAddressTransactionRepository();
            var logRepository     = repositoryFactory.CreateTransactionLogRepository();
            var vmStackRepository = repositoryFactory.CreateTransactionVmStackRepository();

            _repositories.Add(_blockRepository);
            _repositories.Add(_contractRepository);
            _repositories.Add(transactionRepository);
            _repositories.Add(addressTransactionRepository);
            _repositories.Add(logRepository);
            _repositories.Add(vmStackRepository);

            BlockHandler              = new BlockRepositoryHandler(_blockRepository);
            TransactionHandler        = new TransactionRepositoryHandler(transactionRepository, addressTransactionRepository);
            ContractHandler           = new ContractRepositoryHandler(_contractRepository);
            TransactionVmStackHandler = new TransactionVMStackRepositoryHandler(vmStackRepository);
            TransactionLogHandler     = new TransactionLogRepositoryHandler(logRepository);

            _waitStrategy = new WaitStrategy();
        }
Beispiel #8
0
        protected virtual void AddFilterLogStepStorageHandler(IBlockchainStoreRepositoryFactory repositoryFactory)
        {
            var handler = new FilterLogStorageStepHandler(repositoryFactory.CreateTransactionLogRepository());

            this.FilterLogStep.AddProcessorHandler(handler);
        }
Beispiel #9
0
        protected virtual void AddTransactionReceiptStepStorageHandler(IBlockchainStoreRepositoryFactory repositoryFactory)
        {
            var handler = new TransactionReceiptStorageStepHandler(repositoryFactory.CreateTransactionRepository(), repositoryFactory.CreateAddressTransactionRepository());

            this.TransactionReceiptStep.AddProcessorHandler(handler);
        }
Beispiel #10
0
        protected virtual void AddContractCreationStepStorageHandler(IBlockchainStoreRepositoryFactory repositoryFactory)
        {
            var handler = new ContractCreationStorageStepHandler(repositoryFactory.CreateContractRepository());

            this.ContractCreationStep.AddProcessorHandler(handler);
        }
Beispiel #11
0
        protected virtual void AddBlockStepStorageHandler(IBlockchainStoreRepositoryFactory repositoryFactory)
        {
            var handler = new BlockStorageStepHandler(repositoryFactory.CreateBlockRepository());

            this.BlockStep.AddProcessorHandler(handler);
        }
 protected RepositoryLayerTestBase(IBlockchainStoreRepositoryFactory repositoryFactory)
 {
     _repositoryFactory = repositoryFactory;
 }