Example #1
0
// Timestamp of the block an address was first confirmed in
func AddressFirstSeen(db *levigo.DB, addr string) (timestamp uint, err error) {
	timestamp = uint(0)
	ro := levigo.NewReadOptions()
	defer ro.Close()
	it := db.NewIterator(ro)
	defer it.Close()
	it.Seek([]byte(fmt.Sprintf("%s-txo!", addr)))
	if it.Valid() {
		k := string(it.Key()[:])
		data := strings.Split(k, "!")
		r, _ := db.Get(ro, []byte(fmt.Sprintf("tx!%s", data[1])))
		data = strings.Split(string(r[:]), ":")
		ts, _ := strconv.Atoi(data[0])
		timestamp = uint(ts)
		return
	} else {
		err = errors.New("Address not found")
		return
	}
}
Example #2
0
func GetRange(db *levigo.DB, kStart []byte, kEnd []byte) (values []*KeyValue, err error) {
	ro := levigo.NewReadOptions()
	defer ro.Close()

	it := db.NewIterator(ro)
	defer it.Close()

	it.Seek(kStart)
	endBytes := kEnd
	for {
		if it.Valid() {
			if bytes.Compare(it.Key(), endBytes) > 0 {
				return
			}
			values = append(values, &KeyValue{string(it.Key()[:]), string(it.Value()[:])})
			it.Next()
		} else {
			err = it.GetError()
			return
		}
	}

	return
}
Example #3
0
func NewIterator(db *levigo.DB) *Iterator {
	it := db.NewIterator(levigo.NewReadOptions())
	return &Iterator{it}
}