[#47] Update iterator interface

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-02-08 18:23:08 +03:00 committed by Alex Vanin
parent 75c696a555
commit fd803ef639
5 changed files with 21 additions and 19 deletions

View file

@ -95,13 +95,13 @@ func Get(id []byte) []byte {
}
func List() [][]byte {
it := storage.Find(ctx, []byte{})
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
return list(it)
}
func ListByEpoch(epoch int) [][]byte {
it := storage.Find(ctx, epoch)
it := storage.Find(ctx, epoch, storage.KeysOnly)
return list(it)
}
@ -110,7 +110,7 @@ func ListByCID(epoch int, cid []byte) [][]byte {
var buf interface{} = epoch
prefix := append(buf.([]byte), cid...)
it := storage.Find(ctx, prefix)
it := storage.Find(ctx, prefix, storage.KeysOnly)
return list(it)
}
@ -122,7 +122,7 @@ func ListByNode(epoch int, cid []byte, key interop.PublicKey) [][]byte {
from: key,
}
it := storage.Find(ctx, hdr.ID())
it := storage.Find(ctx, hdr.ID(), storage.KeysOnly)
return list(it)
}
@ -131,7 +131,7 @@ func list(it iterator.Iterator) [][]byte {
var result [][]byte
for iterator.Next(it) {
key := iterator.Key(it).([]byte)
key := iterator.Value(it).([]byte) // iterator MUST BE `storage.KeysOnly`
if len(key) == netmapContractKeyLn {
continue
}

View file

@ -193,9 +193,9 @@ func NewEpoch(epochNum int) bool {
n := common.Vote(ctx, epochID, irKey)
if n >= threshold {
common.RemoveVotes(ctx, epochID)
it := storage.Find(ctx, []byte{})
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
for iterator.Next(it) {
addr := iterator.Key(it).([]byte)
addr := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
if len(addr) != 20 {
continue
}

View file

@ -322,12 +322,12 @@ func ListContainerSizes(epoch int) [][]byte {
key := []byte(estimateKeyPrefix)
key = append(key, buf.([]byte)...)
it := storage.Find(ctx, key)
it := storage.Find(ctx, key, storage.KeysOnly)
var result [][]byte
for iterator.Next(it) {
key := iterator.Key(it).([]byte)
key := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
result = append(result, key)
}
@ -467,9 +467,9 @@ func remove(ctx storage.Context, key interface{}, value []byte) int {
func getAllContainers(ctx storage.Context) [][]byte {
var list [][]byte
it := storage.Find(ctx, []byte{})
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
for iterator.Next(it) {
key := iterator.Key(it).([]byte)
key := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
if len(key) == containerIDSize {
list = append(list, key)
}
@ -577,9 +577,9 @@ func isStorageNode(key interop.PublicKey) bool {
func keysToDelete(epoch int) [][]byte {
results := [][]byte{}
it := storage.Find(ctx, []byte(estimateKeyPrefix))
it := storage.Find(ctx, []byte(estimateKeyPrefix), storage.KeysOnly)
for iterator.Next(it) {
k := iterator.Key(it).([]byte)
k := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
nbytes := k[len(estimateKeyPrefix) : len(k)-32]
var n interface{} = nbytes

View file

@ -477,10 +477,11 @@ func SetConfig(id, key, val []byte) bool {
func ListConfig() []record {
var config []record
it := storage.Find(ctx, configPrefix)
it := storage.Find(ctx, configPrefix, storage.None)
for iterator.Next(it) {
key := iterator.Key(it).([]byte)
val := iterator.Value(it).([]byte)
pair := iterator.Value(it).([]interface{})
key := pair[0].([]byte)
val := pair[1].([]byte)
r := record{key: key[len(configPrefix):], val: val}
config = append(config, r)

View file

@ -320,10 +320,11 @@ func InitConfig(args [][]byte) bool {
func ListConfig() []record {
var config []record
it := storage.Find(ctx, configPrefix)
it := storage.Find(ctx, configPrefix, storage.None)
for iterator.Next(it) {
key := iterator.Key(it).([]byte)
val := iterator.Value(it).([]byte)
pair := iterator.Value(it).([]interface{})
key := pair[0].([]byte)
val := pair[1].([]byte)
r := record{key: key[len(configPrefix):], val: val}
config = append(config, r)