@@ -4,19 +4,15 @@ import (
44 "context"
55 "errors"
66 "fmt"
7- "io/ioutil"
87 "path/filepath"
98 "time"
109
1110 "github.com/btcsuite/btcd/chaincfg"
1211 "github.com/btcsuite/btcutil"
1312 "github.com/lightninglabs/loop/swap"
1413 "github.com/lightningnetwork/lnd/lncfg"
15- "github.com/lightningnetwork/lnd/macaroons"
1614 "google.golang.org/grpc"
1715 "google.golang.org/grpc/credentials"
18-
19- macaroon "gopkg.in/macaroon.v2"
2016)
2117
2218var rpcTimeout = 30 * time .Second
@@ -30,6 +26,8 @@ type LndServices struct {
3026 Invoices InvoicesClient
3127
3228 ChainParams * chaincfg.Params
29+
30+ macaroons * macaroonPouch
3331}
3432
3533// GrpcLndServices constitutes a set of required RPC services.
@@ -40,13 +38,25 @@ type GrpcLndServices struct {
4038}
4139
4240// NewLndServices creates a set of required RPC services.
43- func NewLndServices (lndAddress string , application string ,
44- network string , macPath , tlsPath string ) (
45- * GrpcLndServices , error ) {
41+ func NewLndServices (lndAddress , application , network , macaroonDir ,
42+ tlsPath string ) (* GrpcLndServices , error ) {
43+
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.
46+ if macaroonDir == "" {
47+ return nil , fmt .Errorf ("macarooon dir must be set" )
48+ }
49+
50+ // Now that we've ensured our macaroon directory is set properly, we
51+ // can retrieve our full macaroon pouch from the directory.
52+ macaroons , err := newMacaroonPouch (macaroonDir )
53+ if err != nil {
54+ return nil , fmt .Errorf ("unable to obtain macaroons: %v" , err )
55+ }
4656
4757 // Setup connection with lnd
4858 logger .Infof ("Creating lnd connection to %v" , lndAddress )
49- conn , err := getClientConn (lndAddress , network , macPath , tlsPath )
59+ conn , err := getClientConn (lndAddress , network , tlsPath )
5060 if err != nil {
5161 return nil , err
5262 }
@@ -101,6 +111,7 @@ func NewLndServices(lndAddress string, application string,
101111 Signer : signerClient ,
102112 Invoices : invoicesClient ,
103113 ChainParams : chainParams ,
114+ macaroons : macaroons ,
104115 },
105116 cleanup : cleanup ,
106117 }
@@ -135,7 +146,7 @@ var (
135146 defaultSignerFilename = "signer.macaroon"
136147)
137148
138- func getClientConn (address string , network string , macPath , tlsPath string ) (
149+ func getClientConn (address string , network string , tlsPath string ) (
139150 * grpc.ClientConn , error ) {
140151
141152 // Load the specified TLS certificate and build transport credentials
@@ -154,28 +165,6 @@ func getClientConn(address string, network string, macPath, tlsPath string) (
154165 grpc .WithTransportCredentials (creds ),
155166 }
156167
157- if macPath == "" {
158- macPath = filepath .Join (
159- defaultLndDir , defaultDataDir , defaultChainSubDir ,
160- "bitcoin" , network , defaultAdminMacaroonFilename ,
161- )
162- }
163-
164- // Load the specified macaroon file.
165- macBytes , err := ioutil .ReadFile (macPath )
166- if err == nil {
167- // Only if file is found
168- mac := & macaroon.Macaroon {}
169- if err = mac .UnmarshalBinary (macBytes ); err != nil {
170- return nil , fmt .Errorf ("unable to decode macaroon: %v" ,
171- err )
172- }
173-
174- // Now we append the macaroon credentials to the dial options.
175- cred := macaroons .NewMacaroonCredential (mac )
176- opts = append (opts , grpc .WithPerRPCCredentials (cred ))
177- }
178-
179168 // We need to use a custom dialer so we can also connect to unix sockets
180169 // and not just TCP addresses.
181170 opts = append (
0 commit comments