Exemplo n.º 1
0
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)
}
Exemplo n.º 2
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
}
Exemplo n.º 3
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
}