Example #1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context,
                              ILoggerFactory loggerFactory, WatcherService watcher, IEmailSender emailSender, IRateCache rateCache,
                              IBitcoinService bitcoinService, IGraftWalletService graftWalletService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseAuthentication();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "GRAFT Exchange Broker API V1");
            });

            app.UseMiddleware();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            watcher.Add(rateCache);
            watcher.Add(emailSender);
            watcher.Add(bitcoinService);
            watcher.Add(graftWalletService);

            // comment this line if you want to apply the migrations as a separate process
            context.Database.Migrate();

            BitcoinService.Init(options =>
            {
                options.IsTestNetwork          = Configuration["BitcoinService:NetworkType"] != "MainNet";
                options.TryCount               = 2;
                options.DelayMs                = 2000;
                options.LoggerFactory          = loggerFactory;
                options.DbContext              = context;
                options.BitcoinExtPubKeyString = Configuration["BitcoinService:BitcoinExtPubKeyString"];
            });

            EthereumService.Init(
                ConnectionString,
                loggerFactory,
                Configuration["EthereumService:NetworkType"] != "MainNet",
                Configuration["EthereumService:EthereumPoolWalletPassword"],
                Configuration["EthereumService:EthereumGethNodeUrl"],
                Configuration["EthereumService:EthereumBrokerWallet"],
                Convert.ToDecimal(Configuration["EthereumService:EthereumPoolDrainLimit"]));

            bitcoinService.Ping();

            GraftWalletService.Init(context,
                                    Configuration["GraftWalletService:RpcUrl"],
                                    ConnectionString,
                                    loggerFactory);
        }