Exemple #1
0
func (db *LevelDb) getData(data []byte) ([]database.TxData, error) {
	var list []database.TxData
	key := dataToKey(data, nil, 0)
	iter := db.lDb.NewIterator(util.BytesPrefix(key), nil)
	for iter.Next() {
		item := database.TxData{}
		val := iter.Value()
		var err error
		if len(val) == 32 { // TODO remove this once db has been updated.
			item.TxSha, err = wire.NewShaHash(val)
			if err != nil {
				return nil, err
			}
		} else if len(val) == 72 {
			item.TxSha, err = wire.NewShaHash(val[0:32])
			if err != nil {
				return nil, err
			}
			item.BlockSha, err = wire.NewShaHash(val[32:64])
			if err != nil {
				return nil, err
			}
			b := bytes.NewBuffer(val[64:72])
			binary.Read(b, binary.LittleEndian, &item.Time)
		} else {
			return nil, fmt.Errorf("Non-standard length %d", len(val))
		}
		list = append(list, item)
	}
	iter.Release()
	if err := iter.Error(); err != nil {
		return nil, err
	}
	return list, nil
}
Exemple #2
0
func dataNsSlice(ns byte) *util.Range {
	return util.BytesPrefix([]byte{ns})
}
Exemple #3
0
func dataPrefixSlice(ns, prefix byte) *util.Range {
	return util.BytesPrefix([]byte{ns, prefix})
}