public async Task Persists_And_Returns_Last_Block_Processed() { var filePath = CreateJsonFilePath(); DeleteFile(filePath); try { JsonBlockProgressRepository repo = CreateRepository(filePath); Assert.Null(await repo.GetLastBlockNumberProcessedAsync()); await repo.UpsertProgressAsync((ulong)1); Assert.Equal(1, await repo.GetLastBlockNumberProcessedAsync()); //recreate repo - should read existing file repo = CreateRepository(filePath); Assert.Equal(1, await repo.GetLastBlockNumberProcessedAsync()); } finally { DeleteFile(filePath); } }
public async Task UsingTheIndividualComponents() { TransferMetadata.CurrentChainUrl = BlockchainUrl; var web3 = new Web3.Web3(BlockchainUrl); using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); try { using (var transferIndexer = await azureSearchService.CreateEventIndexer <TransferEvent_ERC20>(AzureTransferIndexName)) { using (var transferProcessor = new EventIndexProcessor <TransferEvent_ERC20>(transferIndexer)) { var logProcessor = new BlockRangeLogsProcessor( web3.Eth.Filters.GetLogs, new ILogProcessor[] { transferProcessor }); var progressRepository = new JsonBlockProgressRepository(CreateJsonFileToHoldProgress()); var progressService = new StaticBlockRangeProgressService( 3146684, 3146694, progressRepository); var batchProcessorService = new LogsProcessor( logProcessor, progressService, maxNumberOfBlocksPerBatch: 2); BlockRange?lastBlockRangeProcessed; do { lastBlockRangeProcessed = await batchProcessorService.ProcessOnceAsync(); } while (lastBlockRangeProcessed != null); Assert.Equal(19, transferIndexer.Indexed); } } } finally { await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); } } }
public async Task When_Initial_Last_Block_Processed_Is_Less_Than_Repo_Returns_Repo_Value() { var filePath = CreateJsonFilePath(); DeleteFile(filePath); try { JsonBlockProgressRepository repo = CreateRepository(filePath); await repo.UpsertProgressAsync(11); repo = CreateRepository(filePath, 10); Assert.Equal(11, await repo.GetLastBlockNumberProcessedAsync()); } finally { DeleteFile(filePath); } }
public async Task CustomComposition() { TransferMetadata.CurrentChainUrl = BlockchainUrl; var blockchainProxyService = new BlockchainProxyService(BlockchainUrl); using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); using (var transferIndexer = await azureSearchService.GetOrCreateEventIndex <TransferEvent_ERC20>(AzureTransferIndexName)) { using (var transferProcessor = new EventIndexProcessor <TransferEvent_ERC20>(transferIndexer)) { var logProcessor = new BlockchainLogProcessor( blockchainProxyService, new ILogProcessor[] { transferProcessor }); var progressRepository = new JsonBlockProgressRepository(CreateJsonFileToHoldProgress()); var progressService = new StaticBlockRangeProgressService( 3146684, 3146694, progressRepository); var batchProcessorService = new BlockchainBatchProcessorService( logProcessor, progressService, maxNumberOfBlocksPerBatch: 2); BlockRange?lastBlockRangeProcessed; do { lastBlockRangeProcessed = await batchProcessorService.ProcessLatestBlocksAsync(); } while (lastBlockRangeProcessed != null); Assert.Equal(19, transferIndexer.Indexed); } } await azureSearchService.DeleteIndexAsync(AzureTransferIndexName); } }
public async Task Last_Block_Processed_Can_Be_Initialised() { var filePath = CreateJsonFilePath(); DeleteFile(filePath); try { JsonBlockProgressRepository repo = CreateRepository(filePath, 10); Assert.Equal(10, await repo.GetLastBlockNumberProcessedAsync()); await repo.UpsertProgressAsync(11); Assert.Equal(11, await repo.GetLastBlockNumberProcessedAsync()); } finally { DeleteFile(filePath); } }
protected virtual IBlockProgressService CreateProgressService(BigInteger from, BigInteger?to) { if (BlockProgressServiceCallBack != null) { return(BlockProgressServiceCallBack.Invoke(from, to)); } var progressRepository = new JsonBlockProgressRepository(PathToJsonProgressFile()); IBlockProgressService progressService = null; if (to == null) { progressService = new BlockProgressService(Web3.Eth.Blocks, from, progressRepository, MinimumBlockConfirmations); } else { progressService = new StaticBlockRangeProgressService(from, to.Value, progressRepository); } return(progressService); }
private IBlockProgressService CreateProgressService(ulong from, ulong?to) { if (_blockProgressServiceCallBack != null) { return(_blockProgressServiceCallBack.Invoke(from, to)); } var progressRepository = new JsonBlockProgressRepository(PathToJsonProgressFile()); IBlockProgressService progressService = null; if (to == null) { progressService = new BlockProgressService(BlockchainProxyService, from, progressRepository, MinimumBlockConfirmations); } else { progressService = new StaticBlockRangeProgressService(from, to.Value, progressRepository); } return(progressService); }
public ILogsProcessorBuilder UseJsonFileForBlockProgress(string jsonFilePath, bool deleteExistingFile = false) { BlockProgressRepository = new JsonBlockProgressRepository(jsonFilePath, deleteExistingFile: deleteExistingFile); return(this); }