Skip to content

Commit

Permalink
updated macaroon paths for LND 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Aug 31, 2018
1 parent fbafb0d commit eefc315
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
7 changes: 4 additions & 3 deletions backends/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"encoding/hex"
"errors"
"io"
"io/ioutil"

"github.com/lightningnetwork/lnd/lnrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"io"
"io/ioutil"
)

type LND struct {
Expand Down Expand Up @@ -45,7 +46,7 @@ func (lnd *LND) Connect() error {
macaroon, err := getMacaroon(lnd.MacaroonFile)

if macaroon == nil && err != nil {
log.Error("Failed to read macaroon file of LND")
log.Error("Failed to read macaroon file of LND: ", err)

} else {
lnd.ctx = metadata.NewOutgoingContext(lnd.ctx, macaroon)
Expand Down
37 changes: 31 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package main

import (
"fmt"
"github.com/jessevdk/go-flags"
"github.com/michael1011/lightningtip/backends"
"github.com/michael1011/lightningtip/database"
"github.com/michael1011/lightningtip/notifications"
"github.com/op/go-logging"
"io/ioutil"
"os"
"os/user"
"path"
"path/filepath"
"runtime"
"strings"

"github.com/jessevdk/go-flags"
"github.com/michael1011/lightningtip/backends"
"github.com/michael1011/lightningtip/database"
"github.com/michael1011/lightningtip/notifications"
"github.com/op/go-logging"
)

const (
Expand Down Expand Up @@ -105,7 +107,7 @@ func initConfig() {
LND: &backends.LND{
GRPCHost: defaultLndGRPCHost,
CertFile: path.Join(getDefaultLndDir(), defaultLndCertFile),
MacaroonFile: path.Join(getDefaultLndDir(), defaultMacaroonFile),
MacaroonFile: getDefaultMacaroon(),
},

Mail: &notifications.Mail{
Expand Down Expand Up @@ -204,6 +206,29 @@ func getDefaultDataDir() (dir string) {
return cleanPath(dir)
}

// If the mainnet macaroon does exists it is preffered over all others
func getDefaultMacaroon() string {
networksDir := filepath.Join(getDefaultLndDir(), "/data/chain/bitcoin/")
mainnetMacaroon := filepath.Join(networksDir, "mainnet/", defaultMacaroonFile)

if _, err := os.Stat(mainnetMacaroon); err == nil {
return mainnetMacaroon
}

networks, err := ioutil.ReadDir(networksDir)

if err == nil && len(networks) != 0 {
for _, subDir := range networks {
if subDir.IsDir() {
return filepath.Join(networksDir, networks[0].Name(), defaultMacaroonFile)
}
}
}

log.Warning("Could not find macaroon file")
return ""
}

func getDefaultLndDir() (dir string) {
homeDir := getHomeDir()

Expand Down
3 changes: 2 additions & 1 deletion sample-lightningTip.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@

# Invoice macaroon file for authentication
# If you are using LND version 0.4.0 or lower use the file admin.macaroon
# For LND version 0.5.0 or higher the macaroon for the mainnet is preferred if it exists
# Set an empty string if you disabled the usage of macaroons (not recommended)
# lnd.macaroonfile = .lnd/invoice.macaroon
# lnd.macaroonfile = .lnd/data/chain/bitcoin/testnet/invoice.macaroon


[Mail]
Expand Down

0 comments on commit eefc315

Please sign in to comment.