public async Task AnyContractAnyLog() { const string QUEUE_NAME = "any-contract-any-log"; var azureQueueFactory = new AzureStorageQueueFactory(_azureConnectionString); try { var queue = await azureQueueFactory.GetOrCreateQueueAsync(QUEUE_NAME); var logProcessor = _web3.Processing.Logs.CreateProcessor(filterLog => queue.AddMessageAsync(filterLog)); //if we need to stop the processor mid execution - call cancel on the token var cancellationTokenSource = new CancellationTokenSource(); //crawl the required block range await logProcessor.ExecuteAsync( toBlockNumber : 3146690, cancellationToken : cancellationTokenSource.Token, startAtBlockNumberIfNotProcessed : 3146684); Assert.Equal(65, await queue.GetApproxMessageCountAsync()); } finally { await azureQueueFactory.DeleteQueueAsync(QUEUE_NAME); } }
public async Task MappingAnEventLogToACustomQueueMessage() { const string QUEUE_NAME = "mapping-from-event-log"; var azureQueueFactory = new AzureStorageQueueFactory(_azureConnectionString); try { var queue = await azureQueueFactory.GetOrCreateQueueAsync <EventLog <TransferEventDTO>, MessageToQueue>( QUEUE_NAME, transferEvent => new MessageToQueue(transferEvent)); var logProcessor = _web3.Processing.Logs.CreateProcessor <TransferEventDTO>( transferEvent => queue.AddMessageAsync(transferEvent)); //if we need to stop the processor mid execution - call cancel on the token var cancellationTokenSource = new CancellationTokenSource(); //crawl the required block range await logProcessor.ExecuteAsync( toBlockNumber : 3146690, cancellationToken : cancellationTokenSource.Token, startAtBlockNumberIfNotProcessed : 3146684); Assert.Equal(13, await queue.GetApproxMessageCountAsync()); } finally { await azureQueueFactory.DeleteQueueAsync(QUEUE_NAME); } }
public async Task EventSpecificCriteria() { const string QUEUE_NAME = "with-event-specific-criteria"; var azureQueueFactory = new AzureStorageQueueFactory(_azureConnectionString); try { var queue = await azureQueueFactory.GetOrCreateQueueAsync(QUEUE_NAME); var minValue = BigInteger.Parse("5000000000000000000"); var logProcessor = _web3.Processing.Logs.CreateProcessor <TransferEventDTO>( action: transferEvent => queue.AddMessageAsync(transferEvent), criteria: transferEvent => transferEvent.Event.Value >= minValue); //if we need to stop the processor mid execution - call cancel on the token var cancellationTokenSource = new CancellationTokenSource(); //crawl the required block range await logProcessor.ExecuteAsync( toBlockNumber : 3146690, cancellationToken : cancellationTokenSource.Token, startAtBlockNumberIfNotProcessed : 3146684); await Task.Delay(2000); //give time for queue to update Assert.Equal(6, await queue.GetApproxMessageCountAsync()); } finally { await azureQueueFactory.DeleteQueueAsync(QUEUE_NAME); } }
public async Task ManyContractsOneEvent() { const string QUEUE_NAME = "many-contracts-one-event"; var azureQueueFactory = new AzureStorageQueueFactory(_azureConnectionString); try { var queue = await azureQueueFactory.GetOrCreateQueueAsync(QUEUE_NAME); var contractAddresses = new[] { "0x109424946d5aa4425b2dc1934031d634cdad3f90", "0x16c45b25c4817bdedfce770f795790795c9505a6" }; var logProcessor = _web3.Processing.Logs.CreateProcessorForContracts <TransferEventDTO>( contractAddresses, transferEvent => queue.AddMessageAsync(transferEvent)); //if we need to stop the processor mid execution - call cancel on the token var cancellationTokenSource = new CancellationTokenSource(); //crawl the required block range await logProcessor.ExecuteAsync( toBlockNumber : 3146690, cancellationToken : cancellationTokenSource.Token, startAtBlockNumberIfNotProcessed : 3146684); Assert.Equal(5, await queue.GetApproxMessageCountAsync()); } finally { await azureQueueFactory.DeleteQueueAsync(QUEUE_NAME); } }
public async Task OneContractAnyLog() { const string QUEUE_NAME = "one-contract-any-log"; var azureQueueFactory = new AzureStorageQueueFactory(_azureConnectionString); try { var queue = await azureQueueFactory.GetOrCreateQueueAsync(QUEUE_NAME); var contractFilter = new NewFilterInput { Address = new[] { "0x109424946d5aa4425b2dc1934031d634cdad3f90" } }; var logProcessor = _web3.Processing.Logs.CreateProcessor( action: filterLog => queue.AddMessageAsync(filterLog), filter: contractFilter); //if we need to stop the processor mid execution - call cancel on the token var cancellationTokenSource = new CancellationTokenSource(); //crawl the required block range await logProcessor.ExecuteAsync( toBlockNumber : 3146690, cancellationToken : cancellationTokenSource.Token, startAtBlockNumberIfNotProcessed : 3146684); Assert.Equal(4, await queue.GetApproxMessageCountAsync()); } finally { await azureQueueFactory.DeleteQueueAsync(QUEUE_NAME); } }
public async Task ManyContractsMultipleEvents() { const string ERC20_QUEUE_NAME = "many-contract-multi-event-erc20"; const string APPROVAL_QUEUE_NAME = "many-contract-multi-event-approval"; var azureQueueFactory = new AzureStorageQueueFactory(_azureConnectionString); try { var erc20Queue = await azureQueueFactory.GetOrCreateQueueAsync(ERC20_QUEUE_NAME); var approvalQueue = await azureQueueFactory.GetOrCreateQueueAsync(APPROVAL_QUEUE_NAME); var erc20TransferProcessor = new EventLogProcessorHandler <TransferEventDTO>(transfer => erc20Queue.AddMessageAsync(transfer)); var approvalProcessor = new EventLogProcessorHandler <ApprovalEventDTO>(approval => approvalQueue.AddMessageAsync(approval)); var logProcessors = new ProcessorHandler <FilterLog>[] { erc20TransferProcessor, approvalProcessor }; var contractAddresses = new[] { "0x9EDCb9A9c4d34b5d6A082c86cb4f117A1394F831", "0xafbfefa496ae205cf4e002dee11517e6d6da3ef6" }; var contractFilter = new NewFilterInput { Address = contractAddresses }; var logProcessor = _web3.Processing.Logs.CreateProcessor(logProcessors, filter: contractFilter); //if we need to stop the processor mid execution - call cancel on the token var cancellationTokenSource = new CancellationTokenSource(); //crawl the required block range await logProcessor.ExecuteAsync( toBlockNumber : 3621716, cancellationToken : cancellationTokenSource.Token, startAtBlockNumberIfNotProcessed : 3621715); Assert.Equal(2, await erc20Queue.GetApproxMessageCountAsync()); Assert.Equal(1, await approvalQueue.GetApproxMessageCountAsync()); } finally { await azureQueueFactory.DeleteQueueAsync(ERC20_QUEUE_NAME); await azureQueueFactory.DeleteQueueAsync(APPROVAL_QUEUE_NAME); } }
public async Task AnyContractMultipleEvents() { const string ERC20_QUEUE_NAME = "any-contract-one-event-erc20"; const string ERC721_QUEUE_NAME = "any-contract-one-event-erc721"; var azureQueueFactory = new AzureStorageQueueFactory(_azureConnectionString); try { var erc20Queue = await azureQueueFactory.GetOrCreateQueueAsync(ERC20_QUEUE_NAME); var erc721Queue = await azureQueueFactory.GetOrCreateQueueAsync(ERC721_QUEUE_NAME); var erc20TransferProcessor = new EventLogProcessorHandler <TransferEventDTO>(transfer => erc20Queue.AddMessageAsync(transfer)); var erc721TransferProcessor = new EventLogProcessorHandler <Erc721TransferEvent>(transfer => erc721Queue.AddMessageAsync(transfer)); var logProcessors = new ProcessorHandler <FilterLog>[] { erc20TransferProcessor, erc721TransferProcessor }; var logProcessor = _web3.Processing.Logs.CreateProcessor(logProcessors); //if we need to stop the processor mid execution - call cancel on the token var cancellationTokenSource = new CancellationTokenSource(); //crawl the required block range await logProcessor.ExecuteAsync( toBlockNumber : 3146690, cancellationToken : cancellationTokenSource.Token, startAtBlockNumberIfNotProcessed : 3146684); Assert.Equal(13, await erc20Queue.GetApproxMessageCountAsync()); Assert.Equal(3, await erc721Queue.GetApproxMessageCountAsync()); } finally { await azureQueueFactory.DeleteQueueAsync(ERC20_QUEUE_NAME); await azureQueueFactory.DeleteQueueAsync(ERC721_QUEUE_NAME); } }
private async Task ClearDown( EventProcessingConfigContext repo, AzureTablesRepositoryFactory cloudTableSetup, IAzureSearchService searchService, AzureStorageQueueFactory subscriberQueueFactory, AzureTablesSubscriberRepositoryFactory azureTablesSubscriberRepositoryFactory) { foreach (var index in repo.SubscriberSearchIndexes) { await searchService.DeleteIndexAsync(index.Name); } foreach (var queue in repo.SubscriberSearchIndexes) { await subscriberQueueFactory.DeleteQueueAsync(queue.Name); } await cloudTableSetup.GetCountersTable().DeleteIfExistsAsync(); await azureTablesSubscriberRepositoryFactory.DeleteTablesAsync(); }