lnd+lncfg: move normalizeNetwork to lncfg
This commit is contained in:
parent
4d238cfa2f
commit
46ef212de4
18
config.go
18
config.go
@ -1048,7 +1048,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
|||||||
cfg.networkDir = filepath.Join(
|
cfg.networkDir = filepath.Join(
|
||||||
cfg.DataDir, defaultChainSubDirname,
|
cfg.DataDir, defaultChainSubDirname,
|
||||||
cfg.registeredChains.PrimaryChain().String(),
|
cfg.registeredChains.PrimaryChain().String(),
|
||||||
normalizeNetwork(cfg.ActiveNetParams.Name),
|
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
// If a custom macaroon directory wasn't specified and the data
|
// If a custom macaroon directory wasn't specified and the data
|
||||||
@ -1082,7 +1082,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
|||||||
// per network in the same fashion as the data directory.
|
// per network in the same fashion as the data directory.
|
||||||
cfg.LogDir = filepath.Join(cfg.LogDir,
|
cfg.LogDir = filepath.Join(cfg.LogDir,
|
||||||
cfg.registeredChains.PrimaryChain().String(),
|
cfg.registeredChains.PrimaryChain().String(),
|
||||||
normalizeNetwork(cfg.ActiveNetParams.Name))
|
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name))
|
||||||
|
|
||||||
// A log writer must be passed in, otherwise we can't function and would
|
// A log writer must be passed in, otherwise we can't function and would
|
||||||
// run into a panic later on.
|
// run into a panic later on.
|
||||||
@ -1280,11 +1280,11 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
|||||||
func (c *Config) localDatabaseDir() string {
|
func (c *Config) localDatabaseDir() string {
|
||||||
return filepath.Join(c.DataDir,
|
return filepath.Join(c.DataDir,
|
||||||
defaultGraphSubDirname,
|
defaultGraphSubDirname,
|
||||||
normalizeNetwork(c.ActiveNetParams.Name))
|
lncfg.NormalizeNetwork(c.ActiveNetParams.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) networkName() string {
|
func (c *Config) networkName() string {
|
||||||
return normalizeNetwork(c.ActiveNetParams.Name)
|
return lncfg.NormalizeNetwork(c.ActiveNetParams.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanAndExpandPath expands environment variables and leading ~ in the
|
// CleanAndExpandPath expands environment variables and leading ~ in the
|
||||||
@ -1619,13 +1619,3 @@ func checkEstimateMode(estimateMode string) error {
|
|||||||
return fmt.Errorf("estimatemode must be one of the following: %v",
|
return fmt.Errorf("estimatemode must be one of the following: %v",
|
||||||
bitcoindEstimateModes[:])
|
bitcoindEstimateModes[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeNetwork returns the common name of a network type used to create
|
|
||||||
// file paths. This allows differently versioned networks to use the same path.
|
|
||||||
func normalizeNetwork(network string) string {
|
|
||||||
if strings.HasPrefix(network, "testnet") {
|
|
||||||
return "testnet"
|
|
||||||
}
|
|
||||||
|
|
||||||
return network
|
|
||||||
}
|
|
||||||
|
@ -87,3 +87,13 @@ func CleanAndExpandPath(path string) string {
|
|||||||
// but the variables can still be expanded via POSIX-style $VARIABLE.
|
// but the variables can still be expanded via POSIX-style $VARIABLE.
|
||||||
return filepath.Clean(os.ExpandEnv(path))
|
return filepath.Clean(os.ExpandEnv(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NormalizeNetwork returns the common name of a network type used to create
|
||||||
|
// file paths. This allows differently versioned networks to use the same path.
|
||||||
|
func NormalizeNetwork(network string) string {
|
||||||
|
if strings.HasPrefix(network, "testnet") {
|
||||||
|
return "testnet"
|
||||||
|
}
|
||||||
|
|
||||||
|
return network
|
||||||
|
}
|
||||||
|
5
lnd.go
5
lnd.go
@ -547,7 +547,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
|||||||
towerDBDir := filepath.Join(
|
towerDBDir := filepath.Join(
|
||||||
cfg.Watchtower.TowerDir,
|
cfg.Watchtower.TowerDir,
|
||||||
cfg.registeredChains.PrimaryChain().String(),
|
cfg.registeredChains.PrimaryChain().String(),
|
||||||
normalizeNetwork(cfg.ActiveNetParams.Name),
|
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
towerDB, err := wtdb.OpenTowerDB(towerDBDir)
|
towerDB, err := wtdb.OpenTowerDB(towerDBDir)
|
||||||
@ -1344,8 +1344,7 @@ func initNeutrinoBackend(cfg *Config, chainDir string) (*neutrino.ChainService,
|
|||||||
// database if needed. We append the normalized network name here to
|
// database if needed. We append the normalized network name here to
|
||||||
// match the behavior of btcwallet.
|
// match the behavior of btcwallet.
|
||||||
dbPath := filepath.Join(
|
dbPath := filepath.Join(
|
||||||
chainDir,
|
chainDir, lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
|
||||||
normalizeNetwork(cfg.ActiveNetParams.Name),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure that the neutrino db path exists.
|
// Ensure that the neutrino db path exists.
|
||||||
|
@ -2533,7 +2533,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
|
|||||||
"with current best block in the main chain: %v", err)
|
"with current best block in the main chain: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
network := normalizeNetwork(r.cfg.ActiveNetParams.Name)
|
network := lncfg.NormalizeNetwork(r.cfg.ActiveNetParams.Name)
|
||||||
activeChains := make([]*lnrpc.Chain, r.cfg.registeredChains.NumActiveChains())
|
activeChains := make([]*lnrpc.Chain, r.cfg.registeredChains.NumActiveChains())
|
||||||
for i, chain := range r.cfg.registeredChains.ActiveChains() {
|
for i, chain := range r.cfg.registeredChains.ActiveChains() {
|
||||||
activeChains[i] = &lnrpc.Chain{
|
activeChains[i] = &lnrpc.Chain{
|
||||||
|
Loading…
Reference in New Issue
Block a user