Example #1
0
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
}
Example #2
0
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
}