tendermint/scripts/wal2json/main.go

51 lines
903 B
Go
Raw Normal View History

/*
wal2json converts binary WAL file to JSON.
Usage:
wal2json <path-to-wal>
*/
2017-10-09 12:10:58 -07:00
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)
}
2017-10-09 12:10:58 -07:00
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))
}
os.Stdout.Write(json)
os.Stdout.Write([]byte("\n"))
2017-10-25 18:54:56 -07:00
if end, ok := msg.Msg.(cs.EndHeightMessage); ok {
os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height)))
}
2017-10-09 12:10:58 -07:00
}
}