@ -11,6 +11,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/aperture/lsat"
"github.com/lightninglabs/aperture/lsat"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightningnetwork/lnd/cert"
"github.com/lightningnetwork/lnd/cert"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc"
@ -28,11 +29,19 @@ var (
defaultLogDirname = "logs"
defaultLogDirname = "logs"
defaultLogFilename = "loopd.log"
defaultLogFilename = "loopd.log"
defaultSqliteDatabaseFileName = "loop_sqlite.db"
defaultLogDir = filepath . Join ( LoopDirBase , defaultLogDirname )
defaultLogDir = filepath . Join ( LoopDirBase , defaultLogDirname )
defaultConfigFile = filepath . Join (
defaultConfigFile = filepath . Join (
LoopDirBase , DefaultNetwork , defaultConfigFilename ,
LoopDirBase , DefaultNetwork , defaultConfigFilename ,
)
)
// defaultSqliteDatabasePath is the default path under which we store
// the SQLite database file.
defaultSqliteDatabasePath = filepath . Join (
LoopDirBase , DefaultNetwork , defaultSqliteDatabaseFileName ,
)
defaultMaxLogFiles = 3
defaultMaxLogFiles = 3
defaultMaxLogFileSize = 10
defaultMaxLogFileSize = 10
defaultLoopOutMaxParts = uint32 ( 5 )
defaultLoopOutMaxParts = uint32 ( 5 )
@ -47,6 +56,12 @@ var (
// TLS key.
// TLS key.
DefaultTLSKeyFilename = "tls.key"
DefaultTLSKeyFilename = "tls.key"
// DatabaseBackendSqlite is the name of the SQLite database backend.
DatabaseBackendSqlite = "sqlite"
// DatabaseBackendPostgres is the name of the Postgres database backend.
DatabaseBackendPostgres = "postgres"
defaultSelfSignedOrganization = "loop autogenerated cert"
defaultSelfSignedOrganization = "loop autogenerated cert"
// defaultLndMacaroon is the default macaroon file we use if the old,
// defaultLndMacaroon is the default macaroon file we use if the old,
@ -127,6 +142,10 @@ type Config struct {
ConfigFile string ` long:"configfile" description:"Path to configuration file." `
ConfigFile string ` long:"configfile" description:"Path to configuration file." `
DataDir string ` long:"datadir" description:"Directory for loopdb." `
DataDir string ` long:"datadir" description:"Directory for loopdb." `
DatabaseBackend string ` long:"databasebackend" description:"The database backend to use for storing all asset related data." choice:"sqlite" choice:"postgres" `
Sqlite * loopdb . SqliteConfig ` group:"sqlite" namespace:"sqlite" `
Postgres * loopdb . PostgresConfig ` group:"postgres" namespace:"postgres" `
TLSCertPath string ` long:"tlscertpath" description:"Path to write the TLS certificate for loop's RPC and REST services." `
TLSCertPath string ` long:"tlscertpath" description:"Path to write the TLS certificate for loop's RPC and REST services." `
TLSKeyPath string ` long:"tlskeypath" description:"Path to write the TLS private key for loop's RPC and REST services." `
TLSKeyPath string ` long:"tlskeypath" description:"Path to write the TLS private key for loop's RPC and REST services." `
TLSExtraIPs [ ] string ` long:"tlsextraip" description:"Adds an extra IP to the generated certificate." `
TLSExtraIPs [ ] string ` long:"tlsextraip" description:"Adds an extra IP to the generated certificate." `
@ -172,9 +191,13 @@ func DefaultConfig() Config {
Server : & loopServerConfig {
Server : & loopServerConfig {
NoTLS : false ,
NoTLS : false ,
} ,
} ,
LoopDir : LoopDirBase ,
LoopDir : LoopDirBase ,
ConfigFile : defaultConfigFile ,
ConfigFile : defaultConfigFile ,
DataDir : LoopDirBase ,
DataDir : LoopDirBase ,
DatabaseBackend : DatabaseBackendSqlite ,
Sqlite : & loopdb . SqliteConfig {
DatabaseFileName : defaultSqliteDatabasePath ,
} ,
LogDir : defaultLogDir ,
LogDir : defaultLogDir ,
MaxLogFiles : defaultMaxLogFiles ,
MaxLogFiles : defaultMaxLogFiles ,
MaxLogFileSize : defaultMaxLogFileSize ,
MaxLogFileSize : defaultMaxLogFileSize ,
@ -276,6 +299,14 @@ func Validate(cfg *Config) error {
)
)
}
}
// We'll also update the database file location as well, if it wasn't
// set.
if cfg . Sqlite . DatabaseFileName == defaultSqliteDatabasePath {
cfg . Sqlite . DatabaseFileName = filepath . Join (
cfg . DataDir , defaultSqliteDatabaseFileName ,
)
}
// If either of these directories do not exist, create them.
// If either of these directories do not exist, create them.
if err := os . MkdirAll ( cfg . DataDir , os . ModePerm ) ; err != nil {
if err := os . MkdirAll ( cfg . DataDir , os . ModePerm ) ; err != nil {
return err
return err