mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-15 04:11:37 +01:00
Merge a54add2c94
into c7191d2913
This commit is contained in:
commit
c53283f505
2 changed files with 47 additions and 0 deletions
|
@ -110,6 +110,7 @@ type config struct {
|
||||||
SigNet bool `long:"signet" description:"Connect to signet"`
|
SigNet bool `long:"signet" description:"Connect to signet"`
|
||||||
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
|
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
|
||||||
Wallet bool `long:"wallet" description:"Connect to wallet"`
|
Wallet bool `long:"wallet" description:"Connect to wallet"`
|
||||||
|
GlobalHomeRoot string `long:"globalhomeroot" description:"Global btcctl root directory"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeAddress returns addr with the passed default port appended if
|
// normalizeAddress returns addr with the passed default port appended if
|
||||||
|
@ -211,6 +212,29 @@ func loadConfig() (*config, []string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if global home root path is set and reassigns the config, datadir,
|
||||||
|
// rpc & rpccert paths to the global root
|
||||||
|
if len(preCfg.GlobalHomeRoot) > 0 {
|
||||||
|
btcdHomeDir = filepath.Join(preCfg.GlobalHomeRoot, "Btcd")
|
||||||
|
btcctlHomeDir = filepath.Join(preCfg.GlobalHomeRoot, "Btcctl")
|
||||||
|
btcwalletHomeDir = filepath.Join(preCfg.GlobalHomeRoot, "Btcwallet")
|
||||||
|
|
||||||
|
if _, err := os.Stat(btcctlHomeDir); os.IsNotExist(err) {
|
||||||
|
perm := os.FileMode(0700)
|
||||||
|
err = os.Mkdir(btcctlHomeDir, perm)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error creating Btcctl directory: %v\n",
|
||||||
|
err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// os.Create(filepath.Join(btcctlHomeDir, "btcctl.conf"))
|
||||||
|
}
|
||||||
|
|
||||||
|
preCfg.ConfigFile = filepath.Join(btcctlHomeDir, "btcctl.conf")
|
||||||
|
cfg.RPCCert = filepath.Join(btcdHomeDir, "rpc.cert")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Show the version and exit if the version flag was specified.
|
// Show the version and exit if the version flag was specified.
|
||||||
appName := filepath.Base(os.Args[0])
|
appName := filepath.Base(os.Args[0])
|
||||||
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
|
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
|
||||||
|
@ -245,6 +269,7 @@ func loadConfig() (*config, []string, error) {
|
||||||
// Load additional config from file.
|
// Load additional config from file.
|
||||||
parser := flags.NewParser(&cfg, flags.Default)
|
parser := flags.NewParser(&cfg, flags.Default)
|
||||||
err = flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile)
|
err = flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*os.PathError); !ok {
|
if _, ok := err.(*os.PathError); !ok {
|
||||||
fmt.Fprintf(os.Stderr, "Error parsing config file: %v\n",
|
fmt.Fprintf(os.Stderr, "Error parsing config file: %v\n",
|
||||||
|
|
22
config.go
22
config.go
|
@ -125,6 +125,7 @@ type config struct {
|
||||||
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
|
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
|
||||||
Generate bool `long:"generate" description:"Generate (mine) bitcoins using the CPU"`
|
Generate bool `long:"generate" description:"Generate (mine) bitcoins using the CPU"`
|
||||||
FreeTxRelayLimit float64 `long:"limitfreerelay" description:"Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute"`
|
FreeTxRelayLimit float64 `long:"limitfreerelay" description:"Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute"`
|
||||||
|
GlobalHomeRoot string `short:"g" long:"globalhomeroot" description:"Global root home directory"`
|
||||||
Listeners []string `long:"listen" description:"Add an interface/port to listen for connections (default all interfaces port: 8333, testnet: 18333)"`
|
Listeners []string `long:"listen" description:"Add an interface/port to listen for connections (default all interfaces port: 8333, testnet: 18333)"`
|
||||||
LogDir string `long:"logdir" description:"Directory to log output."`
|
LogDir string `long:"logdir" description:"Directory to log output."`
|
||||||
MaxOrphanTxs int `long:"maxorphantx" description:"Max number of orphan transactions to keep in memory"`
|
MaxOrphanTxs int `long:"maxorphantx" description:"Max number of orphan transactions to keep in memory"`
|
||||||
|
@ -480,6 +481,26 @@ func loadConfig() (*config, []string, error) {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if global home root path is set and reassigns the config, datadir,
|
||||||
|
// rpc & rpccert paths to the global root
|
||||||
|
if len(preCfg.GlobalHomeRoot) > 0 && preCfg.GlobalHomeRoot != defaultHomeDir{
|
||||||
|
defaultHomeDir = filepath.Join(preCfg.GlobalHomeRoot, "Btcd")
|
||||||
|
|
||||||
|
if _, err := os.Stat(defaultHomeDir); os.IsNotExist(err) {
|
||||||
|
perm := os.FileMode(0700)
|
||||||
|
err = os.Mkdir(defaultHomeDir, perm)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error creating Btcd directory: %v\n",
|
||||||
|
err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
preCfg.ConfigFile = filepath.Join(defaultHomeDir, defaultConfigFilename)
|
||||||
|
cfg.DataDir = filepath.Join(defaultHomeDir, defaultDataDirname)
|
||||||
|
cfg.RPCKey = filepath.Join(defaultHomeDir, "rpc.key")
|
||||||
|
cfg.RPCCert = filepath.Join(defaultHomeDir, "rpc.cert")
|
||||||
|
}
|
||||||
|
|
||||||
// Load additional config from file.
|
// Load additional config from file.
|
||||||
var configFileError error
|
var configFileError error
|
||||||
parser := newConfigParser(&cfg, &serviceOpts, flags.Default)
|
parser := newConfigParser(&cfg, &serviceOpts, flags.Default)
|
||||||
|
@ -1186,6 +1207,7 @@ func createDefaultConfigFile(destinationPath string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sampleConfigPath := filepath.Join(path, sampleConfigFilename)
|
sampleConfigPath := filepath.Join(path, sampleConfigFilename)
|
||||||
|
|
||||||
// We generate a random user and password
|
// We generate a random user and password
|
||||||
|
|
Loading…
Add table
Reference in a new issue