OSDN Git Service

update GetAccountIDByAccountAlias
authorChengcheng Zhang <943420582@qq.com>
Thu, 27 Jun 2019 14:48:32 +0000 (22:48 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 27 Jun 2019 14:48:32 +0000 (22:48 +0800)
account/accounts.go
account/image.go
account/store.go
database/account_store.go

index 488cf12..f173388 100644 (file)
@@ -128,7 +128,7 @@ func (m *Manager) SaveAccount(account *Account) error {
        m.accountMu.Lock()
        defer m.accountMu.Unlock()
 
-       if existed := m.store.GetAccountByAccountAlias(account.Alias); existed != nil {
+       if existed := m.store.GetAccountIDByAccountAlias(account.Alias); existed != "" {
                return ErrDuplicateAlias
        }
 
@@ -153,7 +153,7 @@ func (m *Manager) Create(xpubs []chainkd.XPub, quorum int, alias string, deriveR
        m.accountMu.Lock()
        defer m.accountMu.Unlock()
 
-       if existed := m.store.GetAccountByAccountAlias(alias); existed != nil {
+       if existed := m.store.GetAccountIDByAccountAlias(alias); existed != "" {
                return nil, ErrDuplicateAlias
        }
 
@@ -184,7 +184,7 @@ func (m *Manager) UpdateAccountAlias(accountID string, newAlias string) error {
        oldAlias := account.Alias
 
        normalizedAlias := strings.ToLower(strings.TrimSpace(newAlias))
-       if existed := m.store.GetAccountByAccountAlias(normalizedAlias); existed != nil {
+       if existed := m.store.GetAccountIDByAccountAlias(normalizedAlias); existed != "" {
                return ErrDuplicateAlias
        }
 
@@ -333,12 +333,11 @@ func (m *Manager) FindByAlias(alias string) (*Account, error) {
                return m.FindByID(cachedID.(string))
        }
 
-       rawID := m.store.GetAccountByAccountAlias(alias)
-       if rawID == nil {
+       accountID := m.store.GetAccountIDByAccountAlias(alias)
+       if accountID == "" {
                return nil, ErrFindAccount
        }
 
-       accountID := string(rawID)
        m.cacheMu.Lock()
        m.aliasCache.Add(alias, accountID)
        m.cacheMu.Unlock()
index ed8d926..b3094e1 100644 (file)
@@ -60,7 +60,7 @@ func (m *Manager) Restore(image *Image) error {
                        }).Warning("skip restore account due to already existed")
                        continue
                }
-               if existed := m.store.GetAccountByAccountAlias(slice.Account.Alias); existed != nil {
+               if existed := m.store.GetAccountIDByAccountAlias(slice.Account.Alias); existed != "" {
                        return ErrDuplicateAlias
                }
 
index 60d164c..8774636 100644 (file)
@@ -10,8 +10,8 @@ import (
 type AccountStorer interface {
        InitBatch()
        CommitBatch()
-       SetAccount(account *Account, updateIndex bool) error
-       GetAccountByAccountAlias(string) []byte
+       SetAccount(*Account, bool) error
+       GetAccountIDByAccountAlias(string) string
        GetAccountByAccountID(string) []byte
        GetAccountIndex([]chainkd.XPub) []byte
        DeleteAccountByAccountAlias(string)
index e7f502b..0b92527 100644 (file)
@@ -76,9 +76,11 @@ func (store *AccountStore) DeleteAccount(accountID, accountAlias string) {
        }
 }
 
-// GetAccountByAccountAlias get account by account alias
-func (store *AccountStore) GetAccountByAccountAlias(accountAlias string) []byte {
-       return store.accountDB.Get(accountAliasKey(accountAlias))
+// GetAccountIDByAccountAlias get account ID by account alias
+func (store *AccountStore) GetAccountIDByAccountAlias(accountAlias string) string {
+       accountID := store.accountDB.Get(accountAliasKey(accountAlias))
+
+       return string(accountID)
 }
 
 // GetAccountByAccountID get account by accountID