Merge pull request #5135 from GameXG/master

lnd: fix #1990 LND can't read .cookie file in Bitcoin datadir (Windows 10)
This commit is contained in:
Oliver Gugger 2021-04-23 08:41:26 +02:00 committed by GitHub
commit 2e9e4567ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,7 +11,6 @@ import (
"net" "net"
"os" "os"
"os/user" "os/user"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -1642,7 +1641,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
@ -1652,17 +1651,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 {