OSDN Git Service

update GetContractIndex
[bytom/vapor.git] / database / account_store.go
index e7f502b..78c85d4 100644 (file)
@@ -76,19 +76,32 @@ 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
-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
-func (store *AccountStore) GetAccountIndex(xpubs []chainkd.XPub) []byte {
-       return store.accountDB.Get(accountIndexKey(xpubs))
+func (store *AccountStore) GetAccountIndex(xpubs []chainkd.XPub) uint64 {
+       currentIndex := uint64(0)
+       if rawIndexBytes := store.accountDB.Get(accountIndexKey(xpubs)); rawIndexBytes != nil {
+               currentIndex = common.BytesToUnit64(rawIndexBytes)
+       }
+       return currentIndex
 }
 
 // DeleteAccountByAccountAlias delete account by account alias
@@ -141,8 +154,12 @@ func (store *AccountStore) DeleteContractIndex(accountID string) {
 }
 
 // GetContractIndex get contract index
-func (store *AccountStore) GetContractIndex(accountID string) []byte {
-       return store.accountDB.Get(contractIndexKey(accountID))
+func (store *AccountStore) GetContractIndex(accountID string) uint64 {
+       index := uint64(0)
+       if rawIndexBytes := store.accountDB.Get(contractIndexKey(accountID)); rawIndexBytes != nil {
+               index = common.BytesToUnit64(rawIndexBytes)
+       }
+       return index
 }
 
 // GetAccountUTXOs get account utxos by account id