public async Task IndexTransferEventAndFunction() { using (var processor = new AzureEventIndexingProcessor(AzureSearchServiceName, _azureSearchApiKey, BlockchainUrl)) { await ClearDown(processor); try { //reusable function handler which incorporates a function indexer //the function indexer won't do anything yet //it must be linked to an event processor before functions are indexed var transferFunctionHandler = await processor.CreateFunctionHandlerAsync <TransferFunction>(TransferFunctionIndexName); //reusable function handler which incorporates a function indexer //the function indexer won't do anything yet //it must be linked to an event processor before functions are indexed var transferFromFunctionHandler = await processor.CreateFunctionHandlerAsync <TransferFromFunction>(TransferFromFunctionIndexName); //create an indexer for the transfer event //link our function handlers so that functions related to the event are indexed await processor.AddAsync <TransferEvent_ERC20>(TransferEventIndexName, new ITransactionHandler[] { transferFunctionHandler, transferFromFunctionHandler }); //process the range await processor.ProcessAsync(3900007, 3900030); //allow time for azure indexing to finish await Task.Delay(TimeSpan.FromSeconds(5)); //ensure we have written to the expected indexes long transferEventCount = await processor.SearchService.CountDocumentsAsync(TransferEventIndexName); long transferFunctionCount = await processor.SearchService.CountDocumentsAsync(TransferFunctionIndexName); long transferFromFunctionCount = await processor.SearchService.CountDocumentsAsync(TransferFromFunctionIndexName); Assert.Equal(32, transferEventCount); Assert.Equal(1, transferFunctionCount); Assert.Equal(3, transferFromFunctionCount); } finally { await ClearDown(processor); } } }
public async Task StoringCustomSearchDocuments() { using (var processor = new AzureEventIndexingProcessor(AzureSearchServiceName, _azureSearchApiKey, BlockchainUrl)) { await ClearDown(processor); try { //define our azure index for transfer function data var transferFunctionIndex = new Index { Name = TransferFunctionIndexName, Fields = new List <Field> { new Field("TransactionHash", DataType.String) { IsKey = true, IsSearchable = true }, new Field("BlockNumber", DataType.String) { IsSearchable = true }, new Field("BlockTimestamp", DataType.String), new Field("To", DataType.String), new Field("Value", DataType.String) } }; //define azure index for transfer event data var transferEventIndex = new Index { Name = TransferEventIndexName, Fields = new List <Field> { new Field("DocumentKey", DataType.String) { IsKey = true }, new Field("From", DataType.String) { IsSearchable = true, IsFacetable = true }, new Field("To", DataType.String) { IsSearchable = true, IsFacetable = true }, new Field("Value", DataType.String) } }; //reusable function handler which incorporates a function indexer //the function indexer won't do anything yet //it must be linked to an event processor before functions are indexed var transferFunctionHandler = await processor .CreateFunctionHandlerAsync <TransferFunction, CustomTransferFunctionSearchDocument>( transferFunctionIndex, (tx) => new CustomTransferFunctionSearchDocument { TransactionHash = tx.Tx.TransactionHash, BlockNumber = tx.Tx.BlockNumber.Value.ToString(), BlockTimestamp = tx.Tx.BlockTimestamp.ToString(), To = tx.Dto.To, Value = tx.Dto.Value.ToString() }); //create an indexer for the transfer event //link our function handlers so that functions related to the event are indexed await processor.AddAsync <TransferEvent_ERC20, CustomTransferEventSearchDocument>( transferEventIndex, (eventLog) => new CustomTransferEventSearchDocument { From = eventLog.Event.From, To = eventLog.Event.To, Value = eventLog.Event.Value.ToString(), DocumentKey = $"{eventLog.Log.TransactionHash}_{eventLog.Log.LogIndex.Value}" } , new ITransactionHandler[] { transferFunctionHandler }); //process the range await processor.ProcessAsync(3146684, 3146694); //allow time for azure indexing to finish await Task.Delay(TimeSpan.FromSeconds(5)); //ensure we have written to the expected indexes long transferEventCount = await processor.SearchService.CountDocumentsAsync(TransferEventIndexName); long transferFunctionCount = await processor.SearchService.CountDocumentsAsync(TransferFunctionIndexName); Assert.Equal(19, transferEventCount); Assert.Equal(2, transferFunctionCount); } finally { await ClearDown(processor); } } }