88 "encoding/hex"
99 "encoding/json"
1010 "errors"
11+ "flag"
1112 "fmt"
1213 "io"
1314 "io/ioutil"
@@ -25,6 +26,7 @@ import (
2526 "github.com/btcsuite/btcd/wire"
2627 "github.com/lightninglabs/faraday/frdrpc"
2728 terminal "github.com/lightninglabs/lightning-terminal"
29+ "github.com/lightninglabs/lightning-terminal/db"
2830 "github.com/lightninglabs/lightning-terminal/litrpc"
2931 "github.com/lightninglabs/lightning-terminal/subservers"
3032 "github.com/lightninglabs/loop/looprpc"
6062 numActiveNodes = 0
6163 numActiveNodesMtx sync.Mutex
6264
63- defaultLndPassphrase = []byte ("default-wallet-password" )
65+ // litDBBackend is a command line flag for specifying the database
66+ // backend to use when starting a LiT daemon.
67+ litDBBackend = flag .String (
68+ "litdbbackend" , terminal .DatabaseBackendBbolt , "Set the " +
69+ "database backend to use when starting a LiT daemon." ,
70+ )
6471)
6572
6673type LitNodeConfig struct {
@@ -80,6 +87,9 @@ type LitNodeConfig struct {
8087 LitTLSCertPath string
8188 LitMacPath string
8289
90+ DBBackend string
91+ PostgresConfig * db.PostgresConfig
92+
8393 UIPassword string
8494 LitDir string
8595 FaradayDir string
@@ -220,8 +230,20 @@ func (cfg *LitNodeConfig) defaultLitdArgs() *litArgs {
220230 "restcors" : "*" ,
221231 "lnd.debuglevel" : "trace,GRPC=error,PEER=info" ,
222232 "lndconnectinterval" : "200ms" ,
233+ "databasebackend" : cfg .DBBackend ,
223234 }
224235 )
236+
237+ if cfg .DBBackend == terminal .DatabaseBackendPostgres {
238+ args ["postgres.host" ] = cfg .PostgresConfig .Host
239+ args ["postgres.port" ] = fmt .Sprintf (
240+ "%d" , cfg .PostgresConfig .Port ,
241+ )
242+ args ["postgres.user" ] = cfg .PostgresConfig .User
243+ args ["postgres.password" ] = cfg .PostgresConfig .Password
244+ args ["postgres.dbname" ] = cfg .PostgresConfig .DBName
245+ }
246+
225247 for _ , arg := range cfg .LitArgs {
226248 parts := strings .Split (arg , "=" )
227249 option := strings .TrimLeft (parts [0 ], "--" )
@@ -417,6 +439,28 @@ func NewNode(t *testing.T, cfg *LitNodeConfig,
417439 cfg .LitTLSCertPath = filepath .Join (cfg .LitDir , "tls.cert" )
418440 cfg .GenerateListeningPorts ()
419441
442+ // Decide which DB backend to use.
443+ switch * litDBBackend {
444+ case terminal .DatabaseBackendSqlite :
445+ cfg .DBBackend = terminal .DatabaseBackendSqlite
446+
447+ case terminal .DatabaseBackendPostgres :
448+ fixture := db .NewTestPgFixture (
449+ t , db .DefaultPostgresFixtureLifetime , true ,
450+ )
451+ t .Cleanup (func () {
452+ fixture .TearDown (t )
453+ })
454+
455+ cfg .DBBackend = terminal .DatabaseBackendPostgres
456+ cfg .PostgresConfig = fixture .GetConfig ()
457+
458+ default :
459+ cfg .DBBackend = terminal .DatabaseBackendBbolt
460+ }
461+
462+ t .Logf ("Using %v database backend" , cfg .DBBackend )
463+
420464 // Generate a random UI password by reading 16 random bytes and base64
421465 // encoding them.
422466 var randomBytes [16 ]byte
0 commit comments