@ -2,34 +2,67 @@ package loopd
import (
"context"
"fmt"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/liquidity"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/swap"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/ticker"
)
// getClient returns an instance of the swap client.
func getClient ( c on fi g * Config , lnd * lndclient . LndServices ) ( * loop . Client ,
func getClient ( c fg * Config , lnd * lndclient . LndServices ) ( * loop . Client ,
func ( ) , error ) {
clientConfig := & loop . ClientConfig {
ServerAddress : c on fi g. Server . Host ,
ProxyAddress : c on fi g. Server . Proxy ,
SwapServerNoTLS : c on fi g. Server . NoTLS ,
TLSPathServer : c on fi g. Server . TLSPath ,
ServerAddress : c fg. Server . Host ,
ProxyAddress : c fg. Server . Proxy ,
SwapServerNoTLS : c fg. Server . NoTLS ,
TLSPathServer : c fg. Server . TLSPath ,
Lnd : lnd ,
MaxLsatCost : btcutil . Amount ( c on fi g. MaxLSATCost ) ,
MaxLsatFee : btcutil . Amount ( c on fi g. MaxLSATFee ) ,
LoopOutMaxParts : c on fi g. LoopOutMaxParts ,
TotalPaymentTimeout : c on fi g. TotalPaymentTimeout ,
MaxPaymentRetries : c on fi g. MaxPaymentRetries ,
MaxLsatCost : btcutil . Amount ( c fg. MaxLSATCost ) ,
MaxLsatFee : btcutil . Amount ( c fg. MaxLSATFee ) ,
LoopOutMaxParts : c fg. LoopOutMaxParts ,
TotalPaymentTimeout : c fg. TotalPaymentTimeout ,
MaxPaymentRetries : c fg. MaxPaymentRetries ,
}
swapClient , cleanUp , err := loop . NewClient ( config . DataDir , clientConfig )
// Now that we know where the database will live, we'll go ahead and
// open up the default implementation of it.
var (
db loopdb . SwapStore
err error
)
switch cfg . DatabaseBackend {
case DatabaseBackendSqlite :
log . Infof ( "Opening sqlite3 database at: %v" ,
cfg . Sqlite . DatabaseFileName )
db , err = loopdb . NewSqliteStore (
cfg . Sqlite , clientConfig . Lnd . ChainParams ,
)
case DatabaseBackendPostgres :
log . Infof ( "Opening postgres database at: %v" ,
cfg . Postgres . DSN ( true ) )
db , err = loopdb . NewPostgresStore (
cfg . Postgres , clientConfig . Lnd . ChainParams ,
)
default :
return nil , nil , fmt . Errorf ( "unknown database backend: %s" ,
cfg . DatabaseBackend )
}
if err != nil {
return nil , nil , fmt . Errorf ( "unable to open database: %v" , err )
}
swapClient , cleanUp , err := loop . NewClient (
cfg . DataDir , db , clientConfig ,
)
if err != nil {
return nil , nil , err
}