forked from YZhenY/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
58 lines (50 loc) · 1.06 KB
/
main.go
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
58
/*
wal2json converts binary WAL file to JSON.
Usage:
wal2json <path-to-wal>
*/
package main
import (
"encoding/json"
"fmt"
"io"
"os"
cs "github.com/tendermint/tendermint/consensus"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("missing one argument: <path-to-wal>")
os.Exit(1)
}
f, err := os.Open(os.Args[1])
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v", err))
}
defer f.Close()
dec := cs.NewWALDecoder(f)
for {
msg, err := dec.Decode()
if err == io.EOF {
break
} else if err != nil {
panic(fmt.Errorf("failed to decode msg: %v", err))
}
json, err := json.Marshal(msg)
if err != nil {
panic(fmt.Errorf("failed to marshal msg: %v", err))
}
_, err = os.Stdout.Write(json)
if err == nil {
_, err = os.Stdout.Write([]byte("\n"))
}
if err == nil {
if end, ok := msg.Msg.(cs.EndHeightMessage); ok {
_, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height))) // nolint: errcheck, gas
}
}
if err != nil {
fmt.Println("Failed to write message", err)
os.Exit(1)
}
}
}