loopd: extract client configuration

pull/185/head
Joost Jager 4 years ago
parent 65375723b4
commit 5588876b48
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -81,12 +81,38 @@ type Client struct {
clientConfig clientConfig
} }
// NewClient returns a new instance to initiate swaps with. // ClientConfig is the exported configuration structure that is required to
func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool, // instantiate the loop client.
tlsPathServer string, lnd *lndclient.LndServices, maxLSATCost, type ClientConfig struct {
maxLSATFee btcutil.Amount) (*Client, func(), error) { // ServerAddress is the loop server to connect to.
ServerAddress string
// ProxyAddress is the SOCKS proxy that should be used to establish the
// connection.
ProxyAddress string
// Insecure skips TLS when set.
Insecure bool
// TLSPathServer is the path to the TLS certificate that is required to
// connect to the server.
TLSPathServer string
// Lnd is an instance of the lnd proxy.
Lnd *lndclient.LndServices
store, err := loopdb.NewBoltSwapStore(dbDir, lnd.ChainParams) // MaxLsatCost is the maximum price we are willing to pay to the server
// for the token.
MaxLsatCost btcutil.Amount
// MaxLsatFee is the maximum that we are willing to pay in routing fees
// to obtain the token.
MaxLsatFee btcutil.Amount
}
// NewClient returns a new instance to initiate swaps with.
func NewClient(dbDir string, cfg *ClientConfig) (*Client, func(), error) {
store, err := loopdb.NewBoltSwapStore(dbDir, cfg.Lnd.ChainParams)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -95,16 +121,13 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
return nil, nil, err return nil, nil, err
} }
swapServerClient, err := newSwapServerClient( swapServerClient, err := newSwapServerClient(cfg, lsatStore)
serverAddress, proxyAddress, insecure, tlsPathServer, lsatStore,
lnd, maxLSATCost, maxLSATFee,
)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
config := &clientConfig{ config := &clientConfig{
LndServices: lnd, LndServices: cfg.Lnd,
Server: swapServerClient, Server: swapServerClient,
Store: store, Store: store,
LsatStore: lsatStore, LsatStore: lsatStore,
@ -114,11 +137,11 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
} }
sweeper := &sweep.Sweeper{ sweeper := &sweep.Sweeper{
Lnd: lnd, Lnd: cfg.Lnd,
} }
executor := newExecutor(&executorConfig{ executor := newExecutor(&executorConfig{
lnd: lnd, lnd: cfg.Lnd,
store: store, store: store,
sweeper: sweeper, sweeper: sweeper,
createExpiryTimer: config.CreateExpiryTimer, createExpiryTimer: config.CreateExpiryTimer,
@ -127,7 +150,7 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
client := &Client{ client := &Client{
errChan: make(chan error), errChan: make(chan error),
clientConfig: *config, clientConfig: *config,
lndServices: lnd, lndServices: cfg.Lnd,
sweeper: sweeper, sweeper: sweeper,
executor: executor, executor: executor,
resumeReady: make(chan struct{}), resumeReady: make(chan struct{}),

@ -18,11 +18,17 @@ func getClient(config *config, lnd *lndclient.LndServices) (*loop.Client,
return nil, nil, err return nil, nil, err
} }
swapClient, cleanUp, err := loop.NewClient( clientConfig := &loop.ClientConfig{
storeDir, config.SwapServer, config.Proxy, config.Insecure, ServerAddress: config.SwapServer,
config.TLSPathSwapSrv, lnd, btcutil.Amount(config.MaxLSATCost), ProxyAddress: config.Proxy,
btcutil.Amount(config.MaxLSATFee), Insecure: config.Insecure,
) TLSPathServer: config.TLSPathSwapSrv,
Lnd: lnd,
MaxLsatCost: btcutil.Amount(config.MaxLSATCost),
MaxLsatFee: btcutil.Amount(config.MaxLSATFee),
}
swapClient, cleanUp, err := loop.NewClient(storeDir, clientConfig)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

@ -11,7 +11,6 @@ import (
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightninglabs/loop/lndclient"
"github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/lsat" "github.com/lightninglabs/loop/lsat"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
@ -54,17 +53,18 @@ type grpcSwapServerClient struct {
var _ swapServerClient = (*grpcSwapServerClient)(nil) var _ swapServerClient = (*grpcSwapServerClient)(nil)
func newSwapServerClient(address, proxyAddress string, insecure bool, func newSwapServerClient(cfg *ClientConfig, lsatStore lsat.Store) (
tlsPath string, lsatStore lsat.Store, lnd *lndclient.LndServices, *grpcSwapServerClient, error) {
maxLSATCost, maxLSATFee btcutil.Amount) (*grpcSwapServerClient, error) {
// Create the server connection with the interceptor that will handle // Create the server connection with the interceptor that will handle
// the LSAT protocol for us. // the LSAT protocol for us.
clientInterceptor := lsat.NewInterceptor( clientInterceptor := lsat.NewInterceptor(
lnd, lsatStore, serverRPCTimeout, maxLSATCost, maxLSATFee, cfg.Lnd, lsatStore, serverRPCTimeout, cfg.MaxLsatCost,
cfg.MaxLsatFee,
) )
serverConn, err := getSwapServerConn( serverConn, err := getSwapServerConn(
address, proxyAddress, insecure, tlsPath, clientInterceptor, cfg.ServerAddress, cfg.ProxyAddress, cfg.Insecure,
cfg.TLSPathServer, clientInterceptor,
) )
if err != nil { if err != nil {
return nil, err return nil, err

Loading…
Cancel
Save