mirror of
https://github.com/btcsuite/btcd.git
synced 2025-01-18 21:32:30 +01:00
Read RPC username/pass from correct config file for btcctl defaults.
If no existing btcctl.conf file exists, btcctl creates a default one using the RPC username and password from the btcd.conf. If the --wallet flag is passed, however, it should read from btcwallet.conf instead. https://github.com/btcsuite/btcd/issues/875.
This commit is contained in:
parent
01f26a142b
commit
e736ae125d
@ -211,7 +211,15 @@ func loadConfig() (*config, []string, error) {
|
||||
}
|
||||
|
||||
if _, err := os.Stat(preCfg.ConfigFile); os.IsNotExist(err) {
|
||||
err := createDefaultConfigFile(preCfg.ConfigFile)
|
||||
// Use config file for RPC server to create default btcctl config
|
||||
var serverConfigPath string
|
||||
if preCfg.Wallet {
|
||||
serverConfigPath = filepath.Join(btcwalletHomeDir, "btcwallet.conf")
|
||||
} else {
|
||||
serverConfigPath = filepath.Join(btcdHomeDir, "btcd.conf")
|
||||
}
|
||||
|
||||
err := createDefaultConfigFile(preCfg.ConfigFile, serverConfigPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating a default config file: %v\n", err)
|
||||
}
|
||||
@ -272,17 +280,16 @@ func loadConfig() (*config, []string, error) {
|
||||
}
|
||||
|
||||
// createDefaultConfig creates a basic config file at the given destination path.
|
||||
// For this it tries to read the btcd config file at its default path, and extract
|
||||
// the RPC user and password from it.
|
||||
func createDefaultConfigFile(destinationPath string) error {
|
||||
// Read btcd.conf from its default path
|
||||
btcdConfigPath := filepath.Join(btcdHomeDir, "btcd.conf")
|
||||
btcdConfigFile, err := os.Open(btcdConfigPath)
|
||||
// For this it tries to read the config file for the RPC server (either btcd or
|
||||
// btcwallet), and extract the RPC user and password from it.
|
||||
func createDefaultConfigFile(destinationPath, serverConfigPath string) error {
|
||||
// Read the RPC server config
|
||||
serverConfigFile, err := os.Open(serverConfigPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer btcdConfigFile.Close()
|
||||
content, err := ioutil.ReadAll(btcdConfigFile)
|
||||
defer serverConfigFile.Close()
|
||||
content, err := ioutil.ReadAll(serverConfigFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user