package datavisor import ( "ripple/errmsgs" "ripple/state" "ripple/transport" "ripple/types" ) type AccountManager struct { st *state.State sendMgr *transport.AccountSenderManager } func NewAccountManager( st *state.State, sendMgr *transport.AccountSenderManager, ) *AccountManager { m := &AccountManager{ st: st, sendMgr: sendMgr, } m.initializeAccounts() return m } func (m *AccountManager) initializeAccounts() { for id := range m.st.Storage.Accounts { m.sendMgr.AddAccount(id) m.st.Memory.AddAccount(id) } } func (m *AccountManager) AddAccount(id types.UserIdentifier, port int, secretKey [32]byte) error { if id == m.st.Storage.User.UserIdentifier { return errmsgs.ErrInvalidKey } if err := m.st.AddAccount(id, port, secretKey); err != nil { return err } m.sendMgr.AddAccount(id) return nil } func (m *AccountManager) RemoveAccount(id types.UserIdentifier) error { m.sendMgr.RemoveAccount(id) return m.st.RemoveAccount(id) }