func (store *SStorage) setIndex(key []byte, index uint64) error { assert(nil != store.db) assert(nil != key) hs := pb.HardState{Index: index} val, err := hs.Marshal() if nil != err { return err } return store.db.Set(key, val, nil) }
func (store *SStorage) Get(index uint64) (pb.HardState, error) { assert(nil != store.db) key := makeDataKey(index) assert(0 < len(key)) val, err := store.db.Get(key, nil) if nil != err { return pb.HardState{}, err } hs := pb.HardState{} err = hs.Unmarshal(val) if nil != err { return pb.HardState{}, err } return hs, nil }
func (store *SStorage) getIndex(key []byte) (uint64, error) { assert(nil != store.db) assert(nil != key) val, err := store.db.Get(key, nil) if nil != err { if ldb.ErrNotFound == err { return 0, nil } return 0, err } hs := pb.HardState{} err = hs.Unmarshal(val) if nil != err { return 0, err } return hs.Index, nil }