return cachedAccount.(*Account), nil
}
- rawAccount := m.store.GetAccountByAccountID(id)
- if rawAccount == nil {
- return nil, ErrFindAccount
- }
-
- account := &Account{}
- if err := json.Unmarshal(rawAccount, account); err != nil {
+ account, err := m.store.GetAccountByAccountID(id)
+ if err != nil {
return nil, err
}
// GetAccountByProgram return Account by given CtrlProgram
func (m *Manager) GetAccountByProgram(program *CtrlProgram) (*Account, error) {
- rawAccount := m.store.GetAccountByAccountID(program.AccountID)
- if rawAccount == nil {
- return nil, ErrFindAccount
+ account, err := m.store.GetAccountByAccountID(program.AccountID)
+ if err != nil {
+ return nil, err
}
- account := &Account{}
- return account, json.Unmarshal(rawAccount, account)
+ return account, nil
}
// GetAccountByXPubsIndex get account by xPubs and index
// GetAliasByID return the account alias by given ID
func (m *Manager) GetAliasByID(id string) string {
- rawAccount := m.store.GetAccountByAccountID(id)
- if rawAccount == nil {
+ account, err := m.store.GetAccountByAccountID(id)
+ if err != nil {
log.Warn("GetAliasByID fail to find account")
return ""
}
-
- account := &Account{}
- if err := json.Unmarshal(rawAccount, account); err != nil {
- log.Warn(err)
- }
return account.Alias
}
defer m.store.CommitBatch()
for _, slice := range image.Slice {
- if existed := m.store.GetAccountByAccountID(slice.Account.ID); existed != nil {
+ existed, err := m.store.GetAccountByAccountID(slice.Account.ID)
+ if err != nil || existed != nil {
log.WithFields(log.Fields{
"module": logModule,
"alias": slice.Account.Alias,
CommitBatch()
SetAccount(*Account, bool) error
GetAccountIDByAccountAlias(string) string
- GetAccountByAccountID(string) []byte
+ GetAccountByAccountID(string) (*Account, error)
GetAccountIndex([]chainkd.XPub) []byte
DeleteAccountByAccountAlias(string)
DeleteAccountByAccountID(string)
}
// GetAccountByAccountID get account by accountID
-func (store *AccountStore) GetAccountByAccountID(accountID string) []byte {
- return store.accountDB.Get(AccountIDKey(accountID))
+func (store *AccountStore) GetAccountByAccountID(accountID string) (*acc.Account, error) {
+ account := new(acc.Account)
+ rawAccount := store.accountDB.Get(AccountIDKey(accountID))
+ if rawAccount == nil {
+ return nil, acc.ErrFindAccount
+ }
+ if err := json.Unmarshal(rawAccount, account); err != nil {
+ return nil, err
+ }
+ return account, nil
}
// GetAccountIndex get account index by account xpubs