public async Task OneEvent() { const string INDEX_NAME = "transfer-logs"; //surround with "using" so that anything in a buffer is sent on dispose using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { try { //setup var index = await azureSearchService.CreateIndexForEventLogAsync <TransferEvent_ERC20>(INDEX_NAME); var indexer = azureSearchService.CreateIndexerForEventLog <TransferEvent_ERC20>(index.Name, documentsPerBatch: 1); var web3 = new Web3.Web3(BlockchainUrl); var blockchainProcessor = web3.Processing.Logs.CreateProcessor <TransferEvent_ERC20>((transfer) => indexer.IndexAsync(transfer)); var cancellationTokenSource = new CancellationTokenSource(); //execute await blockchainProcessor.ExecuteAsync(3146694, cancellationTokenSource.Token, 3146684); //assert await Task.Delay(5000); // allow time to index Assert.Equal(19, await azureSearchService.CountDocumentsAsync(INDEX_NAME)); } finally { await azureSearchService.DeleteIndexAsync(INDEX_NAME); } } }
public async Task AnEventAndItsTransaction() { const string EVENT_INDEX_NAME = "transfer-logs-related"; const string FUNCTION_INDEX_NAME = "related-transfer-functions"; //surround with "using" so that anything in a buffer is sent on dispose using (var azureSearchService = new AzureSearchService(AzureSearchServiceName, _azureSearchApiKey)) { try { //setup var transferEventIndex = await azureSearchService.CreateIndexForEventLogAsync <TransferEvent_ERC20>(EVENT_INDEX_NAME); var transferFunctionIndex = await azureSearchService.CreateIndexForFunctionMessageAsync <TransferFunction>(FUNCTION_INDEX_NAME); var transferIndexer = azureSearchService.CreateIndexerForEventLog <TransferEvent_ERC20>(transferEventIndex.Name); var transferFunctionIndexer = azureSearchService.CreateIndexerForFunctionMessage <TransferFunction>(transferFunctionIndex.Name); //this handler ensures the transaction is a Transfer and invokes the indexer var transferFunctionProcessorHandler = transferFunctionIndexer.CreateProcessorHandler(); var web3 = new Web3.Web3(BlockchainUrl); var blockchainProcessor = web3.Processing.Logs.CreateProcessor <TransferEvent_ERC20>(async(log) => { await transferIndexer.IndexAsync(log); var transactionWithReceipt = await web3.Eth.GetTransactionReceiptVO(log.Log.BlockNumber, log.Log.TransactionHash).ConfigureAwait(false); await transferFunctionProcessorHandler.ExecuteAsync(transactionWithReceipt); }); var cancellationTokenSource = new CancellationTokenSource(); //execute await blockchainProcessor.ExecuteAsync(3146694, cancellationTokenSource.Token, 3146684); //assert await Task.Delay(5000); // allow time to index Assert.Equal(19, await azureSearchService.CountDocumentsAsync(EVENT_INDEX_NAME)); Assert.Equal(3, await azureSearchService.CountDocumentsAsync(FUNCTION_INDEX_NAME)); } finally { await azureSearchService.DeleteIndexAsync(EVENT_INDEX_NAME); await azureSearchService.DeleteIndexAsync(FUNCTION_INDEX_NAME); } } }