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();
        }
Example #2
0
 public NeoSystem(ProtocolSettings settings, string storageEngine = null, string storagePath = null)
 {
     this.Settings       = settings;
     this.GenesisBlock   = CreateGenesisBlock(settings);
     this.storage_engine = storageEngine;
     this.store          = LoadStore(storagePath);
     this.MemPool        = new MemoryPool(this);
     this.Blockchain     = ActorSystem.ActorOf(Ledger.Blockchain.Props(this));
     this.LocalNode      = ActorSystem.ActorOf(Network.P2P.LocalNode.Props(this));
     this.TaskManager    = ActorSystem.ActorOf(Network.P2P.TaskManager.Props(this));
     this.TxRouter       = ActorSystem.ActorOf(TransactionRouter.Props(this));
     foreach (var plugin in Plugin.Plugins)
     {
         plugin.OnSystemLoaded(this);
     }
     Blockchain.Ask(new Blockchain.Initialize()).Wait();
 }