This repository was archived by the owner on Jan 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtest_iterator.go
More file actions
57 lines (50 loc) · 1.51 KB
/
test_iterator.go
File metadata and controls
57 lines (50 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package operations
import (
"encoding/hex"
"fmt"
"github.com/sei-protocol/sei-db/common/logger"
"github.com/sei-protocol/sei-db/config"
"github.com/sei-protocol/sei-db/ss"
"github.com/spf13/cobra"
)
func TestIteratorCmd() *cobra.Command {
iteratorCmd := &cobra.Command{
Use: "test-iterator",
Short: "Test forward or reverse iterator",
Run: executeIterator,
}
iteratorCmd.PersistentFlags().StringP("home-dir", "d", "/root/.sei", "Database Directory")
iteratorCmd.PersistentFlags().StringP("start", "s", "07", "Start key")
iteratorCmd.PersistentFlags().StringP("end", "e", "08", "End key")
return iteratorCmd
}
func executeIterator(cmd *cobra.Command, _ []string) {
homeDir, _ := cmd.Flags().GetString("home-dir")
start, _ := cmd.Flags().GetString("start")
end, _ := cmd.Flags().GetString("end")
IterateDbData(homeDir, start, end)
}
func IterateDbData(homeDir string, start string, end string) {
ssConfig := config.DefaultStateStoreConfig()
ssConfig.KeepRecent = 0
ssStore, err := ss.NewStateStore(logger.NewNopLogger(), homeDir, ssConfig)
if err != nil {
panic(err)
}
defer ssStore.Close()
if err != nil {
panic(err)
}
fmt.Printf("Start reverse iteration\n")
startPos, _ := hex.DecodeString(start)
endPos, _ := hex.DecodeString(end)
iter, err := ssStore.ReverseIterator("oracle", 98350313, startPos, endPos)
if err != nil {
panic(err)
}
for ; iter.Valid(); iter.Next() {
fmt.Printf("key: %X, value %X\n", iter.Key(), iter.Value())
}
iter.Close()
fmt.Printf("Complete reverse iteration\n")
}