diff --git a/client.go b/client.go index cc39219..1065b8b 100644 --- a/client.go +++ b/client.go @@ -81,12 +81,38 @@ type Client struct { clientConfig } -// NewClient returns a new instance to initiate swaps with. -func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool, - tlsPathServer string, lnd *lndclient.LndServices, maxLSATCost, - maxLSATFee btcutil.Amount) (*Client, func(), error) { +// ClientConfig is the exported configuration structure that is required to +// instantiate the loop client. +type ClientConfig struct { + // 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 { return nil, nil, err } @@ -95,16 +121,13 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool, return nil, nil, err } - swapServerClient, err := newSwapServerClient( - serverAddress, proxyAddress, insecure, tlsPathServer, lsatStore, - lnd, maxLSATCost, maxLSATFee, - ) + swapServerClient, err := newSwapServerClient(cfg, lsatStore) if err != nil { return nil, nil, err } config := &clientConfig{ - LndServices: lnd, + LndServices: cfg.Lnd, Server: swapServerClient, Store: store, LsatStore: lsatStore, @@ -114,11 +137,11 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool, } sweeper := &sweep.Sweeper{ - Lnd: lnd, + Lnd: cfg.Lnd, } executor := newExecutor(&executorConfig{ - lnd: lnd, + lnd: cfg.Lnd, store: store, sweeper: sweeper, createExpiryTimer: config.CreateExpiryTimer, @@ -127,7 +150,7 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool, client := &Client{ errChan: make(chan error), clientConfig: *config, - lndServices: lnd, + lndServices: cfg.Lnd, sweeper: sweeper, executor: executor, resumeReady: make(chan struct{}), diff --git a/loopd/utils.go b/loopd/utils.go index 146841e..bdd70ce 100644 --- a/loopd/utils.go +++ b/loopd/utils.go @@ -18,11 +18,17 @@ func getClient(config *config, lnd *lndclient.LndServices) (*loop.Client, return nil, nil, err } - swapClient, cleanUp, err := loop.NewClient( - storeDir, config.SwapServer, config.Proxy, config.Insecure, - config.TLSPathSwapSrv, lnd, btcutil.Amount(config.MaxLSATCost), - btcutil.Amount(config.MaxLSATFee), - ) + clientConfig := &loop.ClientConfig{ + ServerAddress: config.SwapServer, + ProxyAddress: config.Proxy, + 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 { return nil, nil, err } diff --git a/swap_server_client.go b/swap_server_client.go index 804e882..3e7a7ef 100644 --- a/swap_server_client.go +++ b/swap_server_client.go @@ -11,7 +11,6 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcutil" - "github.com/lightninglabs/loop/lndclient" "github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/lsat" "github.com/lightningnetwork/lnd/lntypes" @@ -54,17 +53,18 @@ type grpcSwapServerClient struct { var _ swapServerClient = (*grpcSwapServerClient)(nil) -func newSwapServerClient(address, proxyAddress string, insecure bool, - tlsPath string, lsatStore lsat.Store, lnd *lndclient.LndServices, - maxLSATCost, maxLSATFee btcutil.Amount) (*grpcSwapServerClient, error) { +func newSwapServerClient(cfg *ClientConfig, lsatStore lsat.Store) ( + *grpcSwapServerClient, error) { // Create the server connection with the interceptor that will handle // the LSAT protocol for us. clientInterceptor := lsat.NewInterceptor( - lnd, lsatStore, serverRPCTimeout, maxLSATCost, maxLSATFee, + cfg.Lnd, lsatStore, serverRPCTimeout, cfg.MaxLsatCost, + cfg.MaxLsatFee, ) serverConn, err := getSwapServerConn( - address, proxyAddress, insecure, tlsPath, clientInterceptor, + cfg.ServerAddress, cfg.ProxyAddress, cfg.Insecure, + cfg.TLSPathServer, clientInterceptor, ) if err != nil { return nil, err