package state import ( "os" "path/filepath" "ripple/config" "ripple/types" ) func Init(configPath string) error { cfg, err := loadConfigFile(configPath) if err != nil { return err } home, err := os.UserHomeDir() if err != nil { return err } if err := os.MkdirAll(filepath.Join(home, config.DataDir), 0o700); err != nil { return err } st := &State{ Storage: Storage{ Port: int(cfg.Port), User: User{ UserIdentifier: types.UserIdentifier{ Username: string(cfg.Username), ServerAddress: string(cfg.ServerAddress), }, SecretKey: [32]byte(cfg.SecretKey), }, Accounts: make(map[types.UserIdentifier]Account), Payments: make(map[[32]byte]Payment), }, } return st.Save() }