Esempio n. 1
0
        private static string CreateDBPath(BTCPayServerOptions opts, string name)
        {
            var dbpath = Path.Combine(opts.DataDir, name);

            if (!Directory.Exists(dbpath))
            {
                Directory.CreateDirectory(dbpath);
            }
            return(dbpath);
        }
Esempio n. 2
0
        public async Task ConfigureAsync(BTCPayServerOptions opts)
        {
            Network  = opts.Network;
            Explorer = new ExplorerClient(opts.Network, opts.Explorer);

            if (!Explorer.SetCookieAuth(opts.CookieFile))
            {
                Explorer.SetNoAuth();
            }

            CancellationTokenSource cts = new CancellationTokenSource(30000);

            try
            {
                Logs.Configuration.LogInformation("Trying to connect to explorer " + Explorer.Address.AbsoluteUri);
                await Explorer.WaitServerStartedAsync(cts.Token).ConfigureAwait(false);

                Logs.Configuration.LogInformation("Connection successfull");
            }
            catch (Exception ex)
            {
                throw new ConfigException($"Could not connect to NBXplorer, {ex.Message}");
            }
            DBreezeEngine db = new DBreezeEngine(CreateDBPath(opts, "TokensDB"));

            _Resources.Add(db);

            db = new DBreezeEngine(CreateDBPath(opts, "InvoiceDB"));
            _Resources.Add(db);

            ApplicationDbContextFactory dbContext = null;

            if (opts.PostgresConnectionString == null)
            {
                var connStr = "Data Source=" + Path.Combine(opts.DataDir, "sqllite.db");
                Logs.Configuration.LogInformation($"SQLite DB used ({connStr})");
                dbContext = new ApplicationDbContextFactory(DatabaseType.Sqlite, connStr);
            }
            else
            {
                Logs.Configuration.LogInformation($"Postgres DB used ({opts.PostgresConnectionString})");
                dbContext = new ApplicationDbContextFactory(DatabaseType.Postgres, opts.PostgresConnectionString);
            }
            DBFactory         = dbContext;
            InvoiceRepository = new InvoiceRepository(dbContext, db, Network);
        }
Esempio n. 3
0
 public void Configure(BTCPayServerOptions opts)
 {
     ConfigureAsync(opts).GetAwaiter().GetResult();
 }