Files
tendermint/scripts/wal2json/main.go
Marko 7e2cc1db5e linter: (1/2) enable errcheck (#5064)
## Description

partially cleanup in preparation for errcheck

i ignored a bunch of defer errors in tests but with the update to go 1.14 we can use `t.Cleanup(func() { if err := <>; err != nil {..}}` to cover those errors, I will do this in pr number two of enabling errcheck.

ref #5059
2020-07-01 15:13:11 +00:00

60 lines
1.1 KiB
Go

/*
wal2json converts binary WAL file to JSON.
Usage:
wal2json <path-to-wal>
*/
package main
import (
"fmt"
"io"
"os"
cs "github.com/tendermint/tendermint/consensus"
tmjson "github.com/tendermint/tendermint/libs/json"
)
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 := tmjson.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 endMsg, ok := msg.Msg.(cs.EndHeightMessage); ok {
_, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", endMsg.Height)))
}
}
if err != nil {
fmt.Println("Failed to write message", err)
os.Exit(1)
}
}
}