public void Creates_TransactionFilter_And_TransactionReceiptFilter() { var builder = new ContractSpecificFilterBuilder(ContractAddress1); Assert.NotNull(builder.TransactionFilter); Assert.NotNull(builder.TransactionReceiptFilter); }
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(); }
public async Task Excludes_Transactions_For_Other_Contracts() { var builder = new ContractSpecificFilterBuilder(ContractAddress1); var tx = new Transaction { To = AnotherAddress }; Assert.False(await builder.FilterContainer.TransactionFilters.IsMatchAsync((tx))); }
public void Creates_FilterContainer_With_TransactionFilter_And_TransactionReceiptFilter() { var builder = new ContractSpecificFilterBuilder(ContractAddress1); Assert.Single(builder.FilterContainer.TransactionFilters); Assert.Single(builder.FilterContainer.TransactionReceiptFilters); Assert.Null(builder.FilterContainer.BlockFilters); Assert.Null(builder.FilterContainer.TransactionAndReceiptFilters); Assert.Null(builder.FilterContainer.TransactionLogFilters); }
public async Task Excludes_Contract_Creation_Calls_For_Other_Contracts() { var builder = new ContractSpecificFilterBuilder(ContractAddress1); var tx = new Transaction { To = null }; var receipt = new TransactionReceipt { ContractAddress = AnotherAddress }; Assert.True(await builder.FilterContainer.TransactionFilters.IsMatchAsync((tx))); Assert.False(await builder.FilterContainer.TransactionReceiptFilters.IsMatchAsync((receipt))); }
public async Task Includes_Calls_To_Contract() { var builder = new ContractSpecificFilterBuilder(ContractAddress1); //tx sent to contract Assert.True(await builder.TransactionFilter.IsMatchAsync( new Transaction { To = ContractAddress1 })); // non contract creation transaction Assert.True(await builder.TransactionReceiptFilter.IsMatchAsync( new TransactionReceipt() { ContractAddress = Extensions.EmptyAddressHex })); }
public async Task Includes_Contract_Creation_Transaction() { var builder = new ContractSpecificFilterBuilder(ContractAddress1); // contract creation tx Assert.True(await builder.TransactionFilter.IsMatchAsync( new Transaction { To = null })); // contract creation receipt Assert.True(await builder.TransactionReceiptFilter.IsMatchAsync( new TransactionReceipt() { ContractAddress = ContractAddress1 })); }
public async Task Supports_Multiple_ContractAddresses() { var builder = new ContractSpecificFilterBuilder(new [] { ContractAddress1, ContractAddress2 }); //tx sent to contract 1 Assert.True(await builder.TransactionFilter.IsMatchAsync( new Transaction { To = ContractAddress1 })); //tx sent to contract 2 Assert.True(await builder.TransactionFilter.IsMatchAsync( new Transaction { To = ContractAddress2 })); //tx sent to another address Assert.False(await builder.TransactionFilter.IsMatchAsync( new Transaction { To = AnotherAddress })); }