Exemple #1
0
        public async void Run(IConfigurationRoot configuration)
        {
            var settings = GetSettings(configuration);
            IServiceCollection collection = new ServiceCollection();

            collection.InitJobDependencies(settings.EthereumCore, settings.SlackNotifications);
            collection.AddSingleton(settings);
            collection.AddTriggers(pool =>
            {
                // default connection must be initialized
                pool.AddDefaultConnection(settings.EthereumCore.Db.DataConnString);
                //// you can add additional connection strings and then specify it in QueueTriggerAttribute
                //pool.AddConnection("custom", additionalConnectionString);
            });

            Services = collection.BuildServiceProvider();
            Services.ActivateRequestInterceptor();
            // restore contract payment events after service shutdown
            //await Task.Run(() => Services.GetService<ProcessManualEvents>().Start());
            //await Task.Run(() => Services.GetService<CatchOldUserContractEvents>().Start());

            Console.WriteLine($"----------- Job is running now {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}-----------");

            RunJobs();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var settings = GetSettings(Configuration);

            services.AddSingleton <IBaseSettings>(settings.EthereumCore);

            services.AddSingleton(settings);

            services.RegisterAzureLogs(settings.EthereumCore, "Api");
            services.RegisterAzureStorages(settings.EthereumCore, settings.SlackNotifications);
            services.RegisterAzureQueues(settings.EthereumCore, settings.SlackNotifications);
            services.RegisterServices();

            ServiceProvider = services.BuildServiceProvider();
            services.RegisterRabbitQueue(settings.EthereumCore, ServiceProvider.GetService <ILog>());

            var builder = services.AddMvc();

            builder.AddMvcOptions(o => { o.Filters.Add(new GlobalExceptionFilter(ServiceProvider.GetService <ILog>())); });

            services.AddSwaggerGen(c =>
            {
                c.SingleApiVersion(new Swashbuckle.Swagger.Model.Info
                {
                    Version = "v1",
                    Title   = "Ethereum.Api"
                });
            });

            ServiceProvider = services.BuildServiceProvider();
            ServiceProvider.ActivateRequestInterceptor();
            return(ServiceProvider);
        }
Exemple #3
0
        //private TestSettings ReadTestSettings()
        //{
        //    try
        //    {
        //        var json = File.ReadAllText(@"..\..\..\generalsettings.json");
        //        if (string.IsNullOrWhiteSpace(json))
        //        {

        //            return null;
        //        }
        //        TestSettings settings = GeneralSettingsReader.ReadSettingsFromData<TestSettings>(json);

        //        return settings;
        //    }
        //    catch (Exception e)
        //    {
        //        return null;
        //    }
        //}

        public async Task Initialize()
        {
            //Constants.StoragePrefix = "tests";

            IServiceCollection collection = new ServiceCollection();
            var settings = ReadSettings();

            //var testSetting = ReadTestSettings();
            Assert.IsNotNull(settings, "Please, provide generalsettings.json file");

            collection.InitJobDependencies(settings.EthereumCore, settings.SlackNotifications);

            Services = collection.BuildServiceProvider();
            Services.ActivateRequestInterceptor();
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            var exit = false;

            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json").AddEnvironmentVariables();
            var configuration = configurationBuilder.Build();

            var settings = GetCurrentSettingsFromUrl();

            SaveSettings(settings);

            IServiceCollection collection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            collection.AddSingleton <IBaseSettings>(settings.EthereumCore);
            collection.AddSingleton <ISlackNotificationSettings>(settings.SlackNotifications);

            RegisterReposExt.RegisterAzureLogs(collection, settings.EthereumCore, "");
            RegisterReposExt.RegisterAzureQueues(collection, settings.EthereumCore, settings.SlackNotifications);
            RegisterReposExt.RegisterAzureStorages(collection, settings.EthereumCore, settings.SlackNotifications);
            ServiceProvider = collection.BuildServiceProvider();
            RegisterRabbitQueueEx.RegisterRabbitQueue(collection, settings.EthereumCore, ServiceProvider.GetService <ILog>());
            RegisterDependency.RegisterServices(collection);
            EthereumJobs.Config.RegisterDependency.RegisterJobs(collection);
            //var web3 = ServiceProvider.GetService<Web3>();
            //web3.Eth.GetBalance.SendRequestAsync("");
            // web3.Eth.Transactions.SendTransaction.SendRequestAsync(new Nethereum.RPC.Eth.DTOs.TransactionInput()
            //{
            //
            //}).Result;
            //var key = EthECKey.GenerateKey().GetPrivateKeyAsBytes();
            //var stringKey = Encoding.Unicode.GetString(key);
            GetAllContractInJson();
            ServiceProvider = collection.BuildServiceProvider();
            ServiceProvider.ActivateRequestInterceptor();
            //var lykkeSigningAPI = ServiceProvider.GetService<ILykkeSigningAPI>();
            //lykkeSigningAPI.ApiEthereumAddkeyPost(new AddKeyRequest()
            //{
            //    Key = "",
            //});

            var service = ServiceProvider.GetService <IErcInterfaceService>();

            service.Transfer("0x5adbf411faf2595698d80b7f93d570dd16d7f4b2", settings.EthereumCore.EthereumMainAccount,
                             "0xae4d8b0c887508750ddb6b32752a82431941e2e7", System.Numerics.BigInteger.Parse("10000000000000000000")).Wait();
            //var paymentService = ServiceProvider.GetService<IPaymentService>();
            //    string result = paymentService.SendEthereum(settings.EthereumMainAccount,
            //    "0xbb0a9c08030898cdaf1f28633f0d3c8556155482", new System.Numerics.BigInteger(5000000000000000)).Result;
            //var coinEv = ServiceProvider.GetService<ICoinEventService>();
            //var ev1 = coinEv.GetCoinEvent("0xbfb8d6a561c1a088c347efb989e19cb02c1028b34a337e001b146fd1360dc714").Result;
            //var ev2 = coinEv.GetCoinEvent("0xa0876a676d695ab145fcf70ac0b2ae02e8b00351a5193352ffb37ad37dce6848").Result;
            //coinEv.InsertAsync(ev1).Wait();
            //coinEv.InsertAsync(ev2).Wait();
            //var paymentService = ServiceProvider.GetService<ICoinTransactionService>();
            //paymentService.PutTransactionToQueue("0xbfb8d6a561c1a088c347efb989e19cb02c1028b34a337e001b146fd1360dc714").Wait();
            //paymentService.PutTransactionToQueue("0xa0876a676d695ab145fcf70ac0b2ae02e8b00351a5193352ffb37ad37dce6848").Wait();
            //var pendingOperationService = ServiceProvider.GetService<IPendingOperationService>();
            //var op = pendingOperationService.GetOperationAsync("40017691-1656-4d71-a8a6-4187200dca73").Result;
            //pendingOperationService.CreateOperation(op).Wait();
            //var op2 = pendingOperationService.GetOperationAsync("41e19fd5-2660-469b-9315-b768f701e742").Result;
            //pendingOperationService.CreateOperation(op2).Wait();

            while (!exit)
            {
                Console.WriteLine("Choose number: ");
                //Console.WriteLine("1. Deploy main contract from local json file");
                Console.WriteLine("2. Deploy main exchange contract");
                Console.WriteLine("3. Deploy coin contract using local json file");
                Console.WriteLine("4. Deploy transfer");
                Console.WriteLine("5. Deploy BCAP Token");
                Console.WriteLine("6. Deploy main exchange contract with multiple owners!(Make sure that jobs are stopped)");
                Console.WriteLine("7. Add more owners to Main Exchange Contract with multiple owners!(Add addresses with some eth on it)");
                Console.WriteLine("9. Deploy And Migrate To NM!(Make sure that jobs are stopped)");
                Console.WriteLine("10. Send transaction to MainExchange!(Make sure that jobs are stopped)");
                Console.WriteLine("0. Exit");

                var input = Console.ReadLine();

                switch (input)
                {
                case "2":
                    DeployMainExchangeContract().Wait();
                    break;

                case "3":
                    DeployCoinContract().Wait();
                    break;

                case "4":
                    DeployTokenTransferContract().Wait();
                    break;

                case "0":
                    exit = true;
                    break;

                case "5":
                    DeployBCAP().Wait();
                    break;

                case "6":
                    DeployAndMigrateMainExchangeContractWithMultipleOwners().Wait();
                    break;

                case "7":
                    AddOwners().Wait();
                    break;

                //case "8":
                //    MigrateAdapter(,).Wait();
                //    break;
                case "9":
                    DeployAndMigrateToNM().Wait();
                    break;

                case "10":
                    SendTransactionFromMainExchange().Wait();
                    break;

                default:
                    Console.WriteLine("Bad input!");
                    continue;
                }

                Console.WriteLine("Done!");
            }
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            var exit = false;

            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json").AddEnvironmentVariables();
            var configuration = configurationBuilder.Build();

            var settings = GetCurrentSettingsFromUrl();

            SaveSettings(settings);

            IServiceCollection collection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            collection.AddSingleton(settings);
            collection.AddSingleton <IBaseSettings>(settings.CurrentValue.EthereumCore);
            collection.AddSingleton <ISlackNotificationSettings>(settings.CurrentValue.SlackNotifications);
            collection.AddSingleton(settings.Nested(x => x.EthereumCore));
            collection.AddSingleton(settings.CurrentValue);
            var consoleLogger = new LogToConsole();

            collection.AddSingleton <ILog>(consoleLogger);

            RegisterReposExt.RegisterAzureQueues(collection, settings.Nested(x => x.EthereumCore), settings.Nested(x => x.SlackNotifications));
            RegisterReposExt.RegisterAzureStorages(collection, settings.Nested(x => x.EthereumCore), settings.Nested(x => x.SlackNotifications));
            ServiceProvider = collection.BuildServiceProvider();
            RegisterRabbitQueueEx.RegisterRabbitQueue(collection, settings.Nested(x => x.EthereumCore), ServiceProvider.GetService <ILog>());
            RegisterDependency.RegisterServices(collection);
            Lykke.Job.EthereumCore.Config.RegisterDependency.RegisterJobs(collection);
            //var web3 = ServiceProvider.GetService<Web3>();
            //web3.Eth.GetBalance.SendRequestAsync("");
            // web3.Eth.Transactions.SendTransaction.SendRequestAsync(new Nethereum.RPC.Eth.DTOs.TransactionInput()
            //{
            //
            //}).Result;
            //var key = EthECKey.GenerateKey().GetPrivateKeyAsBytes();
            //var stringKey = Encoding.Unicode.GetString(key);
            GetAllContractInJson();
            ServiceProvider = collection.BuildServiceProvider();
            ServiceProvider.ActivateRequestInterceptor();
            //var lykkeSigningAPI = ServiceProvider.GetService<ILykkeSigningAPI>();
            //lykkeSigningAPI.ApiEthereumAddkeyPost(new AddKeyRequest()
            //{
            //    Key = "",
            //});

            //var eventService = ServiceProvider.GetService<ITransactionEventsService>();
            //eventService.IndexCashinEventsForAdapter("0x1c4ca817d1c61f9c47ce2bec9d7106393ff981ce",
            //    "0x512867d36f1d6ee43f2056a7c41606133bce514fbc8e911c1834eeae80800ceb").Wait();


            #region DBE TOKEN

            //string tokenAddress;
            //string depositAddress;
            //Contract contract;

            //var web3 = ServiceProvider.GetService<IWeb3>();
            //{
            //    var abi = GetFileContent("Erc20DepositContract.abi");
            //    var bytecode = GetFileContent("Erc20DepositContract.bin");
            //    depositAddress =
            //        ServiceProvider.GetService<IContractService>()
            //        .CreateContract(abi, bytecode, 4000000)
            //        .Result;
            //}
            //{


            //    var abi = GetFileContent("debtoken.abi");
            //    var bytecode = GetFileContent("debtoken.bin");
            //    tokenAddress =
            //        ServiceProvider.GetService<IContractService>()
            //        .CreateContract(abi, bytecode, 4000000)
            //        .Result;
            //    contract = web3.Eth.GetContract(abi, tokenAddress);
            //}

            //{
            //    var unfreezeFunc = contract.GetFunction("unfreeze");
            //    var transactionHash = unfreezeFunc.SendTransactionAsync(settings.CurrentValue.EthereumCore.EthereumMainAccount,
            //                new HexBigInteger(BigInteger.Parse("200000")), new HexBigInteger(0)).Result;
            //}

            //{
            //    var erc20Service = ServiceProvider.GetService<IErcInterfaceService>();
            //    var transactionHash = erc20Service.Transfer(tokenAddress, settings.CurrentValue.EthereumCore.EthereumMainAccount,
            //        depositAddress, System.Numerics.BigInteger.Parse("1000000000000000000")).Result;
            //}


            #endregion

            #region StatusExamples
            //var service = ServiceProvider.GetService<ICoinTransactionService>();
            //{
            //    //fail
            //    var x = service.ProcessTransaction(new Services.Coins.Models.CoinTransactionMessage()
            //    {
            //        TransactionHash = "0xf86efe1b8de285b8255519ca7d0ac76088132e6c5306f88dfc27312c6d7127ea",
            //    }).Result;
            //}

            //{
            //    //ok
            //    var x = service.ProcessTransaction(new Services.Coins.Models.CoinTransactionMessage()
            //    {
            //        TransactionHash = "0xa237230df97a0d6710241597a0186662928afa373c13b8d4eac86f36aa678985",
            //    }).Result;
            //}

            //{
            //    //fail
            //    var x = service.ProcessTransaction(new Services.Coins.Models.CoinTransactionMessage()
            //    {
            //        TransactionHash = "0xb63ac4f94006cbbfe58a1d651e173c56dc74a45e4d1141ac57fc51a0d4202e95",
            //    }).Result;
            //}

            //{
            //    //fail
            //    var x = service.ProcessTransaction(new Services.Coins.Models.CoinTransactionMessage()
            //    {
            //        TransactionHash = "0x1df50ee79d0af8b433f7f0be2a84cbb5dc3e29e5822e78b9c6a7ec33d027e286",
            //    }).Result;
            //}

            //{
            //    //fail
            //    var x = service.ProcessTransaction(new Services.Coins.Models.CoinTransactionMessage()
            //    {
            //        TransactionHash = "0xa3d4c1da523273371fe45c928b9236b353976e7b9e6d2b31e659f7a4c781a764",
            //    }).Result;
            //}

            #endregion

            //0xf86efe1b8de285b8255519ca7d0ac76088132e6c5306f88dfc27312c6d7127ea      0x0
            //0xa237230df97a0d6710241597a0186662928afa373c13b8d4eac86f36aa678985      0x1
            //0xb63ac4f94006cbbfe58a1d651e173c56dc74a45e4d1141ac57fc51a0d4202e95

            var service = ServiceProvider.GetService <IErcInterfaceService>();
            service.Transfer("0x5adbf411faf2595698d80b7f93d570dd16d7f4b2", settings.CurrentValue.EthereumCore.EthereumMainAccount,
                             "0xae4d8b0c887508750ddb6b32752a82431941e2e7", System.Numerics.BigInteger.Parse("10000000000000000000")).Wait();
            //var paymentService = ServiceProvider.GetService<IPaymentService>();
            //    string result = paymentService.SendEthereum(settings.EthereumMainAccount,
            //    "0xbb0a9c08030898cdaf1f28633f0d3c8556155482", new System.Numerics.BigInteger(5000000000000000)).Result;
            //var coinEv = ServiceProvider.GetService<ICoinEventService>();
            //var ev1 = coinEv.GetCoinEvent("0xbfb8d6a561c1a088c347efb989e19cb02c1028b34a337e001b146fd1360dc714").Result;
            //var ev2 = coinEv.GetCoinEvent("0xa0876a676d695ab145fcf70ac0b2ae02e8b00351a5193352ffb37ad37dce6848").Result;
            //coinEv.InsertAsync(ev1).Wait();
            //coinEv.InsertAsync(ev2).Wait();
            //var paymentService = ServiceProvider.GetService<ICoinTransactionService>();
            //paymentService.PutTransactionToQueue("0xbfb8d6a561c1a088c347efb989e19cb02c1028b34a337e001b146fd1360dc714").Wait();
            //paymentService.PutTransactionToQueue("0xa0876a676d695ab145fcf70ac0b2ae02e8b00351a5193352ffb37ad37dce6848").Wait();
            //var pendingOperationService = ServiceProvider.GetService<IPendingOperationService>();
            //var op = pendingOperationService.GetOperationAsync("40017691-1656-4d71-a8a6-4187200dca73").Result;
            //pendingOperationService.CreateOperation(op).Wait();
            //var op2 = pendingOperationService.GetOperationAsync("41e19fd5-2660-469b-9315-b768f701e742").Result;
            //pendingOperationService.CreateOperation(op2).Wait();

            while (!exit)
            {
                Console.WriteLine("Choose number: ");
                //Console.WriteLine("1. Deploy main contract from local json file");
                Console.WriteLine("2. Deploy main exchange contract");
                Console.WriteLine("3. Deploy coin contract using local json file");
                Console.WriteLine("4. Deploy transfer");
                Console.WriteLine("5. Deploy BCAP Token");
                Console.WriteLine("6. Deploy main exchange contract with multiple owners!(Make sure that jobs are stopped)");
                Console.WriteLine("7. Add more owners to Main Exchange Contract with multiple owners!(Add addresses with some eth on it)");
                Console.WriteLine("9. Deploy And Migrate To NM!(Make sure that jobs are stopped)");
                Console.WriteLine("10. Send transaction to MainExchange!(Make sure that jobs are stopped)");
                Console.WriteLine("0. Exit");

                var input = Console.ReadLine();

                switch (input)
                {
                case "2":
                    DeployMainExchangeContract().Wait();
                    break;

                case "3":
                    //DeployCoinContract().Wait();
                    break;

                case "4":
                    DeployTokenTransferContract().Wait();
                    break;

                case "0":
                    exit = true;
                    break;

                case "5":
                    DeployBCAP().Wait();
                    break;

                case "6":
                    DeployAndMigrateMainExchangeContractWithMultipleOwners().Wait();
                    break;

                case "7":
                    AddOwners().Wait();
                    break;

                //case "8":
                //    MigrateAdapter(,).Wait();
                //    break;
                case "9":
                    DeployAndMigrateToNM().Wait();
                    break;

                case "10":
                    SendTransactionFromMainExchange().Wait();
                    break;

                default:
                    Console.WriteLine("Bad input!");
                    continue;
                }

                Console.WriteLine("Done!");
            }
        }