// NewConfig initialize a new usr config and save it to config file.
NewConfig initialize a new usr config and save it to config file.
// NewConfig initialize a new usr config and save it to config file .
func NewConfig(root, secretPhrase, nodeAddr, p2pPort string) error {
	if secretPhrase == "" {
		return ErrSecretPhraseNotProvided
	}
	configFile, err := createConfigFile()
	if err != nil {
		return err
	}
	defer configFile.Close()
	spHash, err := utils.SecureHash(secretPhrase)
	if err != nil {
		return err
	}
	config := &Config{
		Root:         root,
		SecretPhrase: string(spHash),
		NodeAddr:     nodeAddr,
		P2PPort:      p2pPort,
	}
	configData, err := json.MarshalIndent(config, "", "  ")
	if err != nil {
		return err
	}
	_, err = configFile.Write(configData)
	return err
}
func NewConfig ( root , secretPhrase , nodeAddr , p2pPort string ) error { if secretPhrase == " " { return ErrSecretPhraseNotProvided } configFile , err := createConfigFile ( ) if err != nil { return err } defer configFile . Close ( ) spHash , err := utils . SecureHash ( secretPhrase ) if err != nil { return err } config := & Config { Root : root , SecretPhrase : string ( spHash ) , NodeAddr : nodeAddr , P2PPort : p2pPort , } configData , err := json . MarshalIndent ( config , " " , " " ) if err != nil { return err } _ , err = configFile . Write ( configData ) return err }
NewConfig initialize a new usr config and save it to config file.
NewConfig initialize a new usr config and save it to config file .