55 "fmt"
66
77 "github.com/btcsuite/btcd/btcutil"
8+ "github.com/btcsuite/btcd/chaincfg"
89 "github.com/lightninglabs/lndclient"
910 "github.com/lightninglabs/loop"
1011 "github.com/lightninglabs/loop/liquidity"
@@ -15,8 +16,8 @@ import (
1516)
1617
1718// 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 ) {
2021
2122 clientConfig := & loop.ClientConfig {
2223 ServerAddress : cfg .Server .Host ,
@@ -31,26 +32,40 @@ func getClient(cfg *Config, lnd *lndclient.LndServices) (*loop.Client,
3132 MaxPaymentRetries : cfg .MaxPaymentRetries ,
3233 }
3334
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+
3648 var (
37- db loopdb.SwapStore
38- err error
49+ db loopdb.SwapStore
50+ err error
51+ baseDb loopdb.BaseDB
3952 )
4053 switch cfg .DatabaseBackend {
4154 case DatabaseBackendSqlite :
4255 log .Infof ("Opening sqlite3 database at: %v" ,
4356 cfg .Sqlite .DatabaseFileName )
4457 db , err = loopdb .NewSqliteStore (
45- cfg .Sqlite , clientConfig . Lnd . ChainParams ,
58+ cfg .Sqlite , chainParams ,
4659 )
60+ baseDb = * db .(* loopdb.SqliteSwapStore ).BaseDB
4761
4862 case DatabaseBackendPostgres :
4963 log .Infof ("Opening postgres database at: %v" ,
5064 cfg .Postgres .DSN (true ))
5165 db , err = loopdb .NewPostgresStore (
52- cfg .Postgres , clientConfig . Lnd . ChainParams ,
66+ cfg .Postgres , chainParams ,
5367 )
68+ baseDb = * db .(* loopdb.PostgresStore ).BaseDB
5469
5570 default :
5671 return nil , nil , fmt .Errorf ("unknown database backend: %s" ,
@@ -60,14 +75,7 @@ func getClient(cfg *Config, lnd *lndclient.LndServices) (*loop.Client,
6075 return nil , nil , fmt .Errorf ("unable to open database: %v" , err )
6176 }
6277
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
7179}
7280
7381func getLiquidityManager (client * loop.Client ) * liquidity.Manager {
0 commit comments