コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        public async Task IndexingTransferFunctions()
        {
            const string INDEX_NAME = "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 index = await azureSearchService.CreateIndexForFunctionMessageAsync <TransferFunction>(INDEX_NAME);

                    var indexer          = azureSearchService.CreateIndexerForFunctionMessage <TransferFunction>(index.Name, documentsPerBatch: 1);
                    var processorHandler = indexer.CreateProcessorHandler();
                    var web3             = new Web3.Web3(BlockchainUrl);

                    var blockchainProcessor = web3.Processing.Blocks.CreateBlockProcessor((steps) => {
                        steps.TransactionStep.SetMatchCriteria(tx => tx.Transaction.IsFrom("0xf47a8bb5c9ff814d39509591281ae31c0c7c2f38"));
                        steps.TransactionReceiptStep.AddProcessorHandler(processorHandler);
                    });

                    var cancellationTokenSource = new CancellationTokenSource();

                    //execute
                    await blockchainProcessor.ExecuteAsync(3146689, cancellationTokenSource.Token, 3146689);

                    //assert
                    await Task.Delay(5000); // allow time to index

                    Assert.Equal(1, await azureSearchService.CountDocumentsAsync(INDEX_NAME));
                }
                finally
                {
                    await azureSearchService.DeleteIndexAsync(INDEX_NAME);
                }
            }
        }