diff --git a/cmd/btcctl/config.go b/cmd/btcctl/config.go index 9d08a0e2..cd232a9e 100644 --- a/cmd/btcctl/config.go +++ b/cmd/btcctl/config.go @@ -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 }