Exemplo n.º 1
0
        static int Main(string[] args)
        {
            var log = ApplicationLogging.CreateConsoleLogger <Program>().ToILog();

            var appConfig = ConfigurationUtils
                            .Build(args, userSecretsId: "Nethereum.BlockchainStore.MongoDb.UserSecrets");

            var configuration     = BlockchainSourceConfigurationFactory.Get(appConfig);
            var repositoryFactory = MongoDbRepositoryFactory.Create(appConfig);

            return(StorageProcessorConsole.Execute(repositoryFactory, configuration, log: log).Result);
        }
Exemplo n.º 2
0
        public static int Main(string[] args)
        {
            var log = ApplicationLogging.CreateConsoleLogger <Program>().ToILog();

            var appConfig = ConfigurationUtils
                            .Build(args, userSecretsId: "Nethereum.BlockchainStorage.EFCore.Sqlite");

            var blockchainSourceConfiguration = BlockchainSourceConfigurationFactory.Get(appConfig);
            var contextFactory    = new SqliteBlockchainDbContextFactory(appConfig.GetBlockchainStorageConnectionString());
            var repositoryFactory = new BlockchainStoreRepositoryFactory(contextFactory);

            return(StorageProcessorConsole.Execute(repositoryFactory, blockchainSourceConfiguration, log: log).Result);
        }
Exemplo n.º 3
0
        public static int Main(string[] args)
        {
            var log = ApplicationLogging.CreateConsoleLogger <Program>().ToILog();

            var appConfig = ConfigurationUtils
                            .Build(args, userSecretsId: "Nethereum.BlockchainStore.AzureTables");

            var configuration = BlockchainSourceConfigurationFactory.Get(appConfig);

            var connectionString = appConfig[ConnectionStringKey];

            if (string.IsNullOrEmpty(connectionString))
            {
                throw ConfigurationUtils.CreateKeyNotFoundException(ConnectionStringKey);
            }

            var repositoryFactory = new CloudTableSetup(connectionString, configuration.Name);

            return(StorageProcessorConsole.Execute(repositoryFactory, configuration, log: log).Result);
        }
Exemplo n.º 4
0
        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

            var log = ApplicationLogging.CreateConsoleLogger <Program>().ToILog();

            log.Info("CLI args: " + string.Join(" ", args));
            var appConfig = ConfigurationUtils.Build(args);

            var targetBlockchain = BlockchainSourceConfigurationFactory.Get(appConfig);

            log.Info($"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 web3 = new Web3.Web3(targetBlockchain.BlockchainUrl);

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

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

            var blockchainProcessor = new BlockchainProcessor(strategy, log: log);

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

            log.Info($"Contracts Created: {transactionRouter.ContractsCreated}");
            log.Info($"Transactions Handled: {transactionRouter.TransactionsHandled}");

            System.Console.ReadLine();
        }