OSDN Git Service

update GetContractIndex
[bytom/vapor.git] / database / account_store.go
index 0b92527..78c85d4 100644 (file)
@@ -79,18 +79,29 @@ func (store *AccountStore) DeleteAccount(accountID, accountAlias string) {
 // 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
@@ -143,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