You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
903 B

  1. /*
  2. wal2json converts binary WAL file to JSON.
  3. Usage:
  4. wal2json <path-to-wal>
  5. */
  6. package main
  7. import (
  8. "encoding/json"
  9. "fmt"
  10. "io"
  11. "os"
  12. cs "github.com/tendermint/tendermint/consensus"
  13. )
  14. func main() {
  15. if len(os.Args) < 2 {
  16. fmt.Println("missing one argument: <path-to-wal>")
  17. os.Exit(1)
  18. }
  19. f, err := os.Open(os.Args[1])
  20. if err != nil {
  21. panic(fmt.Errorf("failed to open WAL file: %v", err))
  22. }
  23. defer f.Close()
  24. dec := cs.NewWALDecoder(f)
  25. for {
  26. msg, err := dec.Decode()
  27. if err == io.EOF {
  28. break
  29. } else if err != nil {
  30. panic(fmt.Errorf("failed to decode msg: %v", err))
  31. }
  32. json, err := json.Marshal(msg)
  33. if err != nil {
  34. panic(fmt.Errorf("failed to marshal msg: %v", err))
  35. }
  36. os.Stdout.Write(json)
  37. os.Stdout.Write([]byte("\n"))
  38. if end, ok := msg.Msg.(cs.EndHeightMessage); ok {
  39. os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height)))
  40. }
  41. }
  42. }