5
5
"fmt"
6
6
7
7
"github.com/btcsuite/btcd/btcutil"
8
+ "github.com/btcsuite/btcd/chaincfg"
8
9
"github.com/lightninglabs/lndclient"
9
10
"github.com/lightninglabs/loop"
10
11
"github.com/lightninglabs/loop/liquidity"
@@ -15,8 +16,8 @@ import (
15
16
)
16
17
17
18
// getClient returns an instance of the swap client.
18
- func getClient (cfg * Config , lnd * lndclient. LndServices ) ( * loop. Client ,
19
- func (), error ) {
19
+ func getClient (cfg * Config , swapDb loopdb. SwapStore ,
20
+ lnd * lndclient. LndServices ) ( * loop. Client , func (), error ) {
20
21
21
22
clientConfig := & loop.ClientConfig {
22
23
ServerAddress : cfg .Server .Host ,
@@ -31,26 +32,40 @@ func getClient(cfg *Config, lnd *lndclient.LndServices) (*loop.Client,
31
32
MaxPaymentRetries : cfg .MaxPaymentRetries ,
32
33
}
33
34
34
- // Now that we know where the database will live, we'll go ahead and
35
- // open up the default implementation of it.
35
+ swapClient , cleanUp , err := loop .NewClient (
36
+ cfg .DataDir , swapDb , clientConfig ,
37
+ )
38
+ if err != nil {
39
+ return nil , nil , err
40
+ }
41
+
42
+ return swapClient , cleanUp , nil
43
+ }
44
+
45
+ func openDatabase (cfg * Config , chainParams * chaincfg.Params ) (loopdb.SwapStore ,
46
+ * loopdb.BaseDB , error ) { //nolint:unparam
47
+
36
48
var (
37
- db loopdb.SwapStore
38
- err error
49
+ db loopdb.SwapStore
50
+ err error
51
+ baseDb loopdb.BaseDB
39
52
)
40
53
switch cfg .DatabaseBackend {
41
54
case DatabaseBackendSqlite :
42
55
log .Infof ("Opening sqlite3 database at: %v" ,
43
56
cfg .Sqlite .DatabaseFileName )
44
57
db , err = loopdb .NewSqliteStore (
45
- cfg .Sqlite , clientConfig . Lnd . ChainParams ,
58
+ cfg .Sqlite , chainParams ,
46
59
)
60
+ baseDb = * db .(* loopdb.SqliteSwapStore ).BaseDB
47
61
48
62
case DatabaseBackendPostgres :
49
63
log .Infof ("Opening postgres database at: %v" ,
50
64
cfg .Postgres .DSN (true ))
51
65
db , err = loopdb .NewPostgresStore (
52
- cfg .Postgres , clientConfig . Lnd . ChainParams ,
66
+ cfg .Postgres , chainParams ,
53
67
)
68
+ baseDb = * db .(* loopdb.PostgresStore ).BaseDB
54
69
55
70
default :
56
71
return nil , nil , fmt .Errorf ("unknown database backend: %s" ,
@@ -60,14 +75,7 @@ func getClient(cfg *Config, lnd *lndclient.LndServices) (*loop.Client,
60
75
return nil , nil , fmt .Errorf ("unable to open database: %v" , err )
61
76
}
62
77
63
- swapClient , cleanUp , err := loop .NewClient (
64
- cfg .DataDir , db , clientConfig ,
65
- )
66
- if err != nil {
67
- return nil , nil , err
68
- }
69
-
70
- return swapClient , cleanUp , nil
78
+ return db , & baseDb , nil
71
79
}
72
80
73
81
func getLiquidityManager (client * loop.Client ) * liquidity.Manager {
0 commit comments