Skip to content

Commit 5588876

Browse files
committed
loopd: extract client configuration
1 parent 6537572 commit 5588876

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

client.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,38 @@ type Client struct {
8181
clientConfig
8282
}
8383

84-
// NewClient returns a new instance to initiate swaps with.
85-
func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
86-
tlsPathServer string, lnd *lndclient.LndServices, maxLSATCost,
87-
maxLSATFee btcutil.Amount) (*Client, func(), error) {
84+
// ClientConfig is the exported configuration structure that is required to
85+
// instantiate the loop client.
86+
type ClientConfig struct {
87+
// ServerAddress is the loop server to connect to.
88+
ServerAddress string
89+
90+
// ProxyAddress is the SOCKS proxy that should be used to establish the
91+
// connection.
92+
ProxyAddress string
93+
94+
// Insecure skips TLS when set.
95+
Insecure bool
96+
97+
// TLSPathServer is the path to the TLS certificate that is required to
98+
// connect to the server.
99+
TLSPathServer string
100+
101+
// Lnd is an instance of the lnd proxy.
102+
Lnd *lndclient.LndServices
88103

89-
store, err := loopdb.NewBoltSwapStore(dbDir, lnd.ChainParams)
104+
// MaxLsatCost is the maximum price we are willing to pay to the server
105+
// for the token.
106+
MaxLsatCost btcutil.Amount
107+
108+
// MaxLsatFee is the maximum that we are willing to pay in routing fees
109+
// to obtain the token.
110+
MaxLsatFee btcutil.Amount
111+
}
112+
113+
// NewClient returns a new instance to initiate swaps with.
114+
func NewClient(dbDir string, cfg *ClientConfig) (*Client, func(), error) {
115+
store, err := loopdb.NewBoltSwapStore(dbDir, cfg.Lnd.ChainParams)
90116
if err != nil {
91117
return nil, nil, err
92118
}
@@ -95,16 +121,13 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
95121
return nil, nil, err
96122
}
97123

98-
swapServerClient, err := newSwapServerClient(
99-
serverAddress, proxyAddress, insecure, tlsPathServer, lsatStore,
100-
lnd, maxLSATCost, maxLSATFee,
101-
)
124+
swapServerClient, err := newSwapServerClient(cfg, lsatStore)
102125
if err != nil {
103126
return nil, nil, err
104127
}
105128

106129
config := &clientConfig{
107-
LndServices: lnd,
130+
LndServices: cfg.Lnd,
108131
Server: swapServerClient,
109132
Store: store,
110133
LsatStore: lsatStore,
@@ -114,11 +137,11 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
114137
}
115138

116139
sweeper := &sweep.Sweeper{
117-
Lnd: lnd,
140+
Lnd: cfg.Lnd,
118141
}
119142

120143
executor := newExecutor(&executorConfig{
121-
lnd: lnd,
144+
lnd: cfg.Lnd,
122145
store: store,
123146
sweeper: sweeper,
124147
createExpiryTimer: config.CreateExpiryTimer,
@@ -127,7 +150,7 @@ func NewClient(dbDir string, serverAddress, proxyAddress string, insecure bool,
127150
client := &Client{
128151
errChan: make(chan error),
129152
clientConfig: *config,
130-
lndServices: lnd,
153+
lndServices: cfg.Lnd,
131154
sweeper: sweeper,
132155
executor: executor,
133156
resumeReady: make(chan struct{}),

loopd/utils.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ func getClient(config *config, lnd *lndclient.LndServices) (*loop.Client,
1818
return nil, nil, err
1919
}
2020

21-
swapClient, cleanUp, err := loop.NewClient(
22-
storeDir, config.SwapServer, config.Proxy, config.Insecure,
23-
config.TLSPathSwapSrv, lnd, btcutil.Amount(config.MaxLSATCost),
24-
btcutil.Amount(config.MaxLSATFee),
25-
)
21+
clientConfig := &loop.ClientConfig{
22+
ServerAddress: config.SwapServer,
23+
ProxyAddress: config.Proxy,
24+
Insecure: config.Insecure,
25+
TLSPathServer: config.TLSPathSwapSrv,
26+
Lnd: lnd,
27+
MaxLsatCost: btcutil.Amount(config.MaxLSATCost),
28+
MaxLsatFee: btcutil.Amount(config.MaxLSATFee),
29+
}
30+
31+
swapClient, cleanUp, err := loop.NewClient(storeDir, clientConfig)
2632
if err != nil {
2733
return nil, nil, err
2834
}

swap_server_client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/btcsuite/btcd/btcec"
1313
"github.com/btcsuite/btcutil"
14-
"github.com/lightninglabs/loop/lndclient"
1514
"github.com/lightninglabs/loop/looprpc"
1615
"github.com/lightninglabs/loop/lsat"
1716
"github.com/lightningnetwork/lnd/lntypes"
@@ -54,17 +53,18 @@ type grpcSwapServerClient struct {
5453

5554
var _ swapServerClient = (*grpcSwapServerClient)(nil)
5655

57-
func newSwapServerClient(address, proxyAddress string, insecure bool,
58-
tlsPath string, lsatStore lsat.Store, lnd *lndclient.LndServices,
59-
maxLSATCost, maxLSATFee btcutil.Amount) (*grpcSwapServerClient, error) {
56+
func newSwapServerClient(cfg *ClientConfig, lsatStore lsat.Store) (
57+
*grpcSwapServerClient, error) {
6058

6159
// Create the server connection with the interceptor that will handle
6260
// the LSAT protocol for us.
6361
clientInterceptor := lsat.NewInterceptor(
64-
lnd, lsatStore, serverRPCTimeout, maxLSATCost, maxLSATFee,
62+
cfg.Lnd, lsatStore, serverRPCTimeout, cfg.MaxLsatCost,
63+
cfg.MaxLsatFee,
6564
)
6665
serverConn, err := getSwapServerConn(
67-
address, proxyAddress, insecure, tlsPath, clientInterceptor,
66+
cfg.ServerAddress, cfg.ProxyAddress, cfg.Insecure,
67+
cfg.TLSPathServer, clientInterceptor,
6868
)
6969
if err != nil {
7070
return nil, err

0 commit comments

Comments
 (0)