OSDN Git Service

fix the bug (#372)
[bytom/vapor.git] / accesstoken / accesstoken.go
index 7f87270..640f4ae 100644 (file)
@@ -10,9 +10,8 @@ import (
        "strings"
        "time"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/vapor/crypto/sha3pool"
+       dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/errors"
 )
 
@@ -73,7 +72,6 @@ func (cs *CredentialStore) Create(id, typ string) (*Token, error) {
 
        hashedSecret := make([]byte, tokenSize)
        sha3pool.Sum256(hashedSecret, secret)
-
        token := &Token{
                ID:      id,
                Token:   fmt.Sprintf("%s:%x", id, hashedSecret),
@@ -85,8 +83,8 @@ func (cs *CredentialStore) Create(id, typ string) (*Token, error) {
        if err != nil {
                return nil, err
        }
-       cs.DB.Set(key, value)
 
+       cs.DB.Set(key, value)
        return token, nil
 }
 
@@ -96,12 +94,12 @@ func (cs *CredentialStore) Check(id string, secret string) error {
                return errors.WithDetailf(ErrBadID, "invalid id %q", id)
        }
 
-       var value []byte
-       token := &Token{}
-
-       if value = cs.DB.Get([]byte(id)); value == nil {
+       value := cs.DB.Get([]byte(id))
+       if value == nil {
                return errors.WithDetailf(ErrNoMatchID, "check id %q nonexisting", id)
        }
+
+       token := &Token{}
        if err := json.Unmarshal(value, token); err != nil {
                return err
        }