lnd: fix #1990 LND can't read .cookie file in Bitcoin datadir (Windows)

This commit is contained in:
GameXG 2021-03-24 21:47:55 +08:00
parent b1309277b9
commit 2030b506b1

@ -11,7 +11,6 @@ import (
"net" "net"
"os" "os"
"os/user" "os/user"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -1598,7 +1597,7 @@ func extractBitcoindRPCParams(networkName string,
// Next, we'll try to find an auth cookie. We need to detect the chain // Next, we'll try to find an auth cookie. We need to detect the chain
// by seeing if one is specified in the configuration file. // by seeing if one is specified in the configuration file.
dataDir := path.Dir(bitcoindConfigPath) dataDir := filepath.Dir(bitcoindConfigPath)
dataDirRE, err := regexp.Compile(`(?m)^\s*datadir\s*=\s*([^\s]+)`) dataDirRE, err := regexp.Compile(`(?m)^\s*datadir\s*=\s*([^\s]+)`)
if err != nil { if err != nil {
return "", "", "", "", err return "", "", "", "", err
@ -1608,17 +1607,17 @@ func extractBitcoindRPCParams(networkName string,
dataDir = string(dataDirSubmatches[1]) dataDir = string(dataDirSubmatches[1])
} }
chainDir := "/" chainDir := ""
switch networkName { switch networkName {
case "testnet3": case "mainnet":
chainDir = "/testnet3/" chainDir = ""
case "testnet4": case "regtest", "testnet3":
chainDir = "/testnet4/" chainDir = networkName
case "regtest": default:
chainDir = "/regtest/" return "", "", "", "", fmt.Errorf("unexpected networkname %v", networkName)
} }
cookie, err := ioutil.ReadFile(dataDir + chainDir + ".cookie") cookie, err := ioutil.ReadFile(filepath.Join(dataDir, chainDir, ".cookie"))
if err == nil { if err == nil {
splitCookie := strings.Split(string(cookie), ":") splitCookie := strings.Split(string(cookie), ":")
if len(splitCookie) == 2 { if len(splitCookie) == 2 {