예제 #1
0
        public IndexingEvents()
        {
            /*
             * Amazon EWS Search Secrets
             * AWSElasticSearchUrl
             * AWS_ACCESS_KEY_ID
             * AWS_SECRET_ACCESS_KEY
             */

            //user secrets are only for development
            //if not in development the key will be retrieved from environmental variables or command line args
            ConfigurationUtils.SetEnvironmentAsDevelopment();

            //use the command line to set your azure search api key
            //e.g. dotnet user-secrets set "AWS_ACCESS_KEY_ID" "<put key here>"
            var appConfig = ConfigurationUtils
                            .Build(Array.Empty <string>(), userSecretsId: "Nethereum.BlockchainStore.Search.Samples");

            _awsAccessKeyId      = appConfig[ConfigurationKeyNames.AWS_ACCESS_KEY_ID];
            _awsSecretAccessKey  = appConfig[ConfigurationKeyNames.AWS_SECRET_ACCESS_KEY];
            _awsElasticSearchUrl = appConfig[ConfigurationKeyNames.AWSElasticSearchUrl];

            // disable from CI
            var disableElasticSearchValue = appConfig[ConfigurationKeyNames.Disable_Elastic_Search_Samples];

            if (bool.TryParse(disableElasticSearchValue, out bool disable))
            {
                _disableElasticSearch = disable;
            }
        }
        public async Task CreateIndex_Upsert_Suggest_Search()
        {
            ConfigurationUtils.SetEnvironment("development");

            var appConfig = ConfigurationUtils
                            .Build(Array.Empty <string>(), userSecretsId: "Nethereum.BlockchainStore.Search.Tests");

            var apiKey = appConfig[ApiKeyName];

            var eventSearchIndexDefinition = new EventSearchIndexDefinition <TransferEvent>();

            using (var searchService = new AzureEventSearchService(AzureSearchServiceName, apiKey))
            {
                try
                {
                    await searchService.DeleteIndexAsync(eventSearchIndexDefinition);

                    using (var azureIndex = await searchService.GetOrCreateIndex(eventSearchIndexDefinition))
                    {
                        var transferEventLog = new EventLog <TransferEvent>(
                            new TransferEvent
                        {
                            From  = "0x9209b29f2094457d3dba62d1953efea58176ba27",
                            To    = "0x1209b29f2094457d3dba62d1953efea58176ba28",
                            Value = new HexBigInteger("2000000")
                        },
                            new FilterLog
                        {
                            Address          = "0x26bc47888b7bfdf77db41ec0a2fb4db00af1c92a",
                            TransactionHash  = "0xcb00b69d2594a3583309f332ada97d0df48bae00170e36a4f7bbdad7783fc7e5",
                            BlockNumber      = new HexBigInteger(7118507),
                            BlockHash        = "0x337cd6feedafac6abba40eff40fb1957e08985180f5a03016924ef72fc7b04b9",
                            LogIndex         = new HexBigInteger(0),
                            Removed          = false,
                            TransactionIndex = new HexBigInteger(0)
                        });

                        await azureIndex.UpsertAsync(transferEventLog);

                        await Task.Delay(TimeSpan.FromSeconds(5));

                        var suggestion = await azureIndex.SuggestAsync(transferEventLog.Log.BlockNumber.Value.ToString());

                        Assert.NotNull(suggestion);
                        Assert.Equal(1, suggestion.Results.Count);

                        var searchResult = await azureIndex.SearchAsync(
                            transferEventLog.Event.From);

                        Assert.NotNull(searchResult);
                        Assert.Equal(1, searchResult.Results.Count);
                    }
                }
                finally
                {
                    await searchService.DeleteIndexAsync(eventSearchIndexDefinition);
                }
            }
        }
        public AzureTableStorageExamples()
        {
            _web3 = new Web3.Web3(URL);
            ConfigurationUtils.SetEnvironmentAsDevelopment();
            var config = ConfigurationUtils.Build(args: Array.Empty <string>(), userSecretsId: "Nethereum.BlockchainStore.AzureTables");

            _azureConnectionString = config["AzureStorageConnectionString"];
        }
        private static string GetConnectionString()
        {
            var config = ConfigurationUtils.Build();
            var connectionStringName = $"BlockchainDbStorageDesignTime";
            var connectionString     = config.GetConnectionString(connectionStringName);

            return(connectionString);
        }
        public AzureTablesFixture()
        {
            ConfigurationUtils.SetEnvironmentAsDevelopment();
            var appConfig        = ConfigurationUtils.Build(CommandLineArgs, UserSecretsId);
            var connectionString = appConfig["AzureStorageConnectionString"];

            Factory = new AzureTablesRepositoryFactory(connectionString, "UnitTest");
        }
        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 MongoDbFixture()
        {
            ConfigurationUtils.SetEnvironmentAsDevelopment();
            var appConfig = ConfigurationUtils.Build(CommandLineArgs);

            appConfig.SetMongoDbConnectionString(MongoDbConnectionString);

            Factory = MongoDbRepositoryFactory.Create(appConfig, deleteAllExistingCollections: true);
        }
예제 #8
0
        public static int Main(string[] args)
        {
            var appConfig         = ConfigurationUtils.Build(args).AddConsoleLogging();
            var contextFactory    = new SqliteBlockchainDbContextFactory("BlockchainDbContext");
            var repositoryFactory = new BlockchainStoreRepositoryFactory(contextFactory);
            var configuration     = BlockchainSourceConfigurationFactory.Get(appConfig);

            configuration.ProcessBlockTransactionsInParallel = false;
            return(ProcessorConsole.Execute(repositoryFactory, configuration).Result);
        }
        static int Main(string[] args)
        {
            var appConfig = ConfigurationUtils
                            .Build(args, userSecretsId: "Nethereum.BlockchainStore.CosmosCore.UserSecrets")
                            .AddConsoleLogging();

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

            return(StorageProcessorConsole.Execute(repositoryFactory, configuration).Result);
        }
예제 #10
0
        public static IConfigurationRoot LoadConfig()
        {
            ConfigurationUtils.SetEnvironmentAsDevelopment();

            //use the command line to set your azure search api key
            //e.g. dotnet user-secrets set "AzureStorageConnectionString" "<put key here>"
            var appConfig = ConfigurationUtils
                            .Build(Array.Empty <string>(), userSecretsId: TestConfiguration.USER_SECRETS_ID);

            return(appConfig);
        }
        static int Main(string[] args)
        {
            var appConfig = ConfigurationUtils
                            .Build(args, userSecretsId: "Nethereum.BlockchainStore.Csv.UserSecrets")
                            .AddConsoleLogging();

            var configuration     = BlockchainSourceConfigurationFactory.Get(appConfig);
            var outputPath        = appConfig["CsvOutputPath"];
            var repositoryFactory = new CsvBlockchainStoreRepositoryFactory(outputPath);

            return(StorageProcessorConsole.Execute(repositoryFactory, configuration).Result);
        }
예제 #12
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);
        }
예제 #13
0
        public static int Main(string[] args)
        {
            var appConfig = ConfigurationUtils
                            .Build(args, userSecretsId: "Nethereum.BlockchainStorage.EFCore.Sqlite")
                            .AddConsoleLogging();

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

            return(ProcessorConsole.Execute(repositoryFactory, blockchainSourceConfiguration).Result);
        }
예제 #14
0
        public static int Main(string[] args)
        {
            var appConfig = ConfigurationUtils
                            .Build(args, userSecretsId: "Nethereum.BlockchainStorage.EFCore.SqlServer")
                            .AddConsoleLogging();

            var blockchainConfig  = BlockchainSourceConfigurationFactory.Get(appConfig);
            var dbContextFactory  = SqlServerCoreBlockchainDbContextFactory.Create(appConfig);
            var repositoryFactory = new BlockchainStoreRepositoryFactory(dbContextFactory);

            return(ProcessorConsole.Execute(repositoryFactory, blockchainConfig).Result);
        }
예제 #15
0
        public IndexingTransferEvents()
        {
            //user secrets are only for development
            //if not in development the key will be retrieved from environmental variables or command line args
            ConfigurationUtils.SetEnvironmentAsDevelopment();

            //use the command line to set your azure search api key
            //e.g. dotnet user-secrets set "AzureSearchApiKey" "<put key here>"
            var appConfig = ConfigurationUtils
                            .Build(Array.Empty <string>(), userSecretsId: "Nethereum.BlockchainStore.Search.Samples");

            _azureSearchApiKey = appConfig[ApiKeyName];
        }
예제 #16
0
        public CosmosFixture()
        {
            ConfigurationUtils.SetEnvironment("development");
            var appConfig = ConfigurationUtils.Build(CommandLineArgs);

            //Azure Cosmos DB emulator settings
            //https://localhost:8081/_explorer/index.html

            appConfig.SetCosmosEndpointUri("https://localhost:8081");
            appConfig.SetCosmosAccessKey(
                "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");

            Factory = CosmosRepositoryFactory.Create(appConfig, deleteAllExistingCollections: true);
        }
        public AzureTablesFixture()
        {
            /*
             * To run the tests setup the connection string in the user secrets
             * In the command line navigate to folder: Nethereum.BlockchainStorage\src\Nethereum.BlockchainStore.AzureTables.Tests
             * Set the connection string using the syntax below
             * dotnet user-secrets set "AzureStorageConnectionString" "CONNECTION_STRING"
             */

            ConfigurationUtils.SetEnvironmentAsDevelopment();
            var appConfig        = ConfigurationUtils.Build(CommandLineArgs, UserSecretsId);
            var connectionString = appConfig["AzureStorageConnectionString"];

            Factory = new AzureTablesRepositoryFactory(connectionString, "UnitTest");
        }
예제 #18
0
 public StorageProcessorConsole(
     string[] consoleArgs,
     string userSecretsId,
     Func <IConfigurationRoot, TRepositoryFactory> createRepositoryFactoryCallback,
     Action <TRepositoryFactory> disposeRepositoriesCallback = null
     )
 {
     log.Info("StorageProcessorConsole constructor");
     ConsoleArgs   = consoleArgs;
     UserSecretsId = userSecretsId;
     CreateRepositoryFactoryCallback = createRepositoryFactoryCallback;
     DisposeAction       = disposeRepositoriesCallback;
     Configuration       = ConfigurationUtils.Build(ConsoleArgs, userSecretsId: UserSecretsId);
     TargetConfiguration = BlockchainSourceConfigurationFactory.Get(Configuration);
 }
예제 #19
0
        public static int Main(string[] args)
        {
            var appConfig     = ConfigurationUtils.Build(args, userSecretsId: "Nethereum.BlockchainStore.AzureTables");
            var configuration = BlockchainSourceConfigurationPresets.Get(appConfig);

            var connectionString = appConfig[ConnectionStringKey];

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

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

            return(ProcessorConsole.Execute(repositoryFactory, configuration).Result);
        }
예제 #20
0
        public CosmosFixture()
        {
            ConfigurationUtils.SetEnvironmentAsDevelopment();
            var appConfig = ConfigurationUtils.Build(CommandLineArgs);

            appConfig.SetCosmosEndpointUri(CosmosEmulatorBaseUrl);
            appConfig.SetCosmosAccessKey(CosmosAccessKey);

            if (!IsEmulatorRunning())
            {
                string message = $"The Cosmos DB Emulator is not running at Uri '{CosmosEmulatorBaseUrl}'";

                if (File.Exists(EmulatorPath))
                {
                    throw new Exception(message);
                }

                throw new Exception($"{message}.  The emulator does not appear to be installed (at least not in the default location '{EmulatorPath}').");
            }

            Factory = CosmosRepositoryFactory.Create(appConfig, deleteAllExistingCollections: true);
        }