Skip to content

Commit 6d00809

Browse files
committed
cmd/loopd+lndclient: based on the network, update the macaron path if unset
1 parent 5f6ad11 commit 6d00809

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

cmd/loopd/daemon.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func daemon(config *config) error {
3434

3535
// Create an instance of the loop client library.
3636
swapClient, cleanup, err := getClient(
37-
config.Network, config.SwapServer, config.Insecure, &lnd.LndServices,
37+
config.Network, config.SwapServer, config.Insecure,
38+
&lnd.LndServices,
3839
)
3940
if err != nil {
4041
return err

lndclient/lnd_services.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,38 @@ type GrpcLndServices struct {
4141
func NewLndServices(lndAddress, application, network, macaroonDir,
4242
tlsPath string) (*GrpcLndServices, error) {
4343

44-
// If the macaroon directory isn't set, then we can't proceed as we
45-
// need then to obtain the macaroons for all sub-servers.
44+
// Based on the network, if the macaroon directory isn't set, then
45+
// we'll use the expected default locations.
4646
if macaroonDir == "" {
47-
return nil, fmt.Errorf("macarooon dir must be set")
47+
switch network {
48+
case "testnet":
49+
macaroonDir = filepath.Join(
50+
defaultLndDir, defaultDataDir,
51+
defaultChainSubDir, "bitcoin", "testnet",
52+
)
53+
54+
case "mainnet":
55+
macaroonDir = filepath.Join(
56+
defaultLndDir, defaultDataDir,
57+
defaultChainSubDir, "bitcoin", "mainnet",
58+
)
59+
60+
case "simnet":
61+
macaroonDir = filepath.Join(
62+
defaultLndDir, defaultDataDir,
63+
defaultChainSubDir, "bitcoin", "simnet",
64+
)
65+
66+
case "regtest":
67+
macaroonDir = filepath.Join(
68+
defaultLndDir, defaultDataDir,
69+
defaultChainSubDir, "bitcoin", "regtest",
70+
)
71+
72+
default:
73+
return nil, fmt.Errorf("unsupported network: %v",
74+
network)
75+
}
4876
}
4977

5078
// Now that we've ensured our macaroon directory is set properly, we
@@ -88,7 +116,7 @@ func NewLndServices(lndAddress, application, network, macaroonDir,
88116
}
89117

90118
// With the network check passed, we'll now initialize the rest of the
91-
// sub-sever connections, giving each of them their specific macaroon.
119+
// sub-server connections, giving each of them their specific macaroon.
92120
notifierClient := newChainNotifierClient(conn, macaroons.chainMac)
93121
signerClient := newSignerClient(conn, macaroons.signerMac)
94122
walletKitClient := newWalletKitClient(conn, macaroons.walletKitMac)

0 commit comments

Comments
 (0)