8
8
"encoding/hex"
9
9
"encoding/json"
10
10
"errors"
11
+ "flag"
11
12
"fmt"
12
13
"io"
13
14
"io/ioutil"
@@ -25,6 +26,7 @@ import (
25
26
"github.com/btcsuite/btcd/wire"
26
27
"github.com/lightninglabs/faraday/frdrpc"
27
28
terminal "github.com/lightninglabs/lightning-terminal"
29
+ "github.com/lightninglabs/lightning-terminal/db"
28
30
"github.com/lightninglabs/lightning-terminal/litrpc"
29
31
"github.com/lightninglabs/lightning-terminal/subservers"
30
32
"github.com/lightninglabs/loop/looprpc"
60
62
numActiveNodes = 0
61
63
numActiveNodesMtx sync.Mutex
62
64
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
+ )
64
71
)
65
72
66
73
type LitNodeConfig struct {
@@ -80,6 +87,9 @@ type LitNodeConfig struct {
80
87
LitTLSCertPath string
81
88
LitMacPath string
82
89
90
+ DBBackend string
91
+ PostgresConfig * db.PostgresConfig
92
+
83
93
UIPassword string
84
94
LitDir string
85
95
FaradayDir string
@@ -220,8 +230,20 @@ func (cfg *LitNodeConfig) defaultLitdArgs() *litArgs {
220
230
"restcors" : "*" ,
221
231
"lnd.debuglevel" : "trace,GRPC=error,PEER=info" ,
222
232
"lndconnectinterval" : "200ms" ,
233
+ "databasebackend" : cfg .DBBackend ,
223
234
}
224
235
)
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
+
225
247
for _ , arg := range cfg .LitArgs {
226
248
parts := strings .Split (arg , "=" )
227
249
option := strings .TrimLeft (parts [0 ], "--" )
@@ -417,6 +439,28 @@ func NewNode(t *testing.T, cfg *LitNodeConfig,
417
439
cfg .LitTLSCertPath = filepath .Join (cfg .LitDir , "tls.cert" )
418
440
cfg .GenerateListeningPorts ()
419
441
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
+
420
464
// Generate a random UI password by reading 16 random bytes and base64
421
465
// encoding them.
422
466
var randomBytes [16 ]byte
0 commit comments