static void Main(string[] args)
        {
            // This particular sample should be run with the following CLI args
            // A random contract on the Rinkeby network was chosen as an example
            // --Blockchain rinkeby --FromBlock   3146650

            System.Console.WriteLine("CLI args: " + string.Join(" ", args));
            var appConfig        = ConfigurationUtils.Build(args).AddConsoleLogging();
            var targetBlockchain = BlockchainSourceConfigurationFactory.Get(appConfig);

            System.Console.WriteLine($"Target Node/Name (URL): {targetBlockchain.Name}, {targetBlockchain.BlockchainUrl}");

            //only process transactions that created or called our contract
            var filters = new ContractSpecificFilterBuilder(ContractAddress).Filters;

            //for specific functions on our contract, output the name and input arg values
            var transactionRouter = new TransactionRouter();

            transactionRouter.AddContractCreationHandler(
                new ContractCreationPrinter <GlitchGoonsItemConstructor>());
            transactionRouter.AddTransactionHandler(new FunctionPrinter <BuyApprenticeFunction>());
            transactionRouter.AddTransactionHandler(new FunctionPrinter <OpenChestFunction>());

            //for specific events, output the values
            var transactionLogRouter = new TransactionLogRouter();

            transactionLogRouter.AddHandler(new EventPrinter <TransferEvent>());

            var handlers = new HandlerContainer()
            {
                TransactionHandler    = transactionRouter,
                TransactionLogHandler = transactionLogRouter,
            };

            var blockchainProxy = new BlockchainProxyService(targetBlockchain.BlockchainUrl);

            var blockProcessor = BlockProcessorFactory.Create(
                blockchainProxy,
                handlers,
                filters,
                processTransactionsInParallel: false);

            var strategy = new ProcessingStrategy(blockProcessor)
            {
                MinimumBlockConfirmations = 6 //wait for 6 block confirmations before processing block
            };

            var blockchainProcessor = new BlockchainProcessor(strategy);

            blockchainProcessor.ExecuteAsync
                (targetBlockchain.FromBlock, targetBlockchain.ToBlock)
            .GetAwaiter().GetResult();

            System.Console.WriteLine($"Contracts Created: {transactionRouter.ContractsCreated}");
            System.Console.WriteLine($"Transactions Handled: {transactionRouter.TransactionsHandled}");

            System.Console.ReadLine();
        }
Beispiel #2
0
        public async Task Handlers_Without_Conditions_Are_Invoked()
        {
            _router.AddTransactionHandler(_mockTransactionHandler.Object);
            await _router.HandleTransactionAsync(_transactionWithReceipt.Object);

            _mockTransactionHandler.Verify(h => h.HandleTransactionAsync(_transactionWithReceipt.Object), Times.Once());
            Assert.Equal(1, _router.TransactionsHandled);
        }