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.

69 lines
1.3 KiB

lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
7 years ago
7 years ago
  1. /*
  2. wal2json converts binary WAL file to JSON.
  3. Usage:
  4. wal2json <path-to-wal>
  5. */
  6. package main
  7. import (
  8. "fmt"
  9. "io"
  10. "os"
  11. amino "github.com/tendermint/go-amino"
  12. cs "github.com/tendermint/tendermint/consensus"
  13. "github.com/tendermint/tendermint/types"
  14. )
  15. var cdc = amino.NewCodec()
  16. func init() {
  17. cs.RegisterMessages(cdc)
  18. cs.RegisterWALMessages(cdc)
  19. types.RegisterBlockAmino(cdc)
  20. }
  21. func main() {
  22. if len(os.Args) < 2 {
  23. fmt.Println("missing one argument: <path-to-wal>")
  24. os.Exit(1)
  25. }
  26. f, err := os.Open(os.Args[1])
  27. if err != nil {
  28. panic(fmt.Errorf("failed to open WAL file: %v", err))
  29. }
  30. defer f.Close()
  31. dec := cs.NewWALDecoder(f)
  32. for {
  33. msg, err := dec.Decode()
  34. if err == io.EOF {
  35. break
  36. } else if err != nil {
  37. panic(fmt.Errorf("failed to decode msg: %v", err))
  38. }
  39. json, err := cdc.MarshalJSON(msg)
  40. if err != nil {
  41. panic(fmt.Errorf("failed to marshal msg: %v", err))
  42. }
  43. _, err = os.Stdout.Write(json)
  44. if err == nil {
  45. _, err = os.Stdout.Write([]byte("\n"))
  46. }
  47. if err == nil {
  48. if endMsg, ok := msg.Msg.(cs.EndHeightMessage); ok {
  49. _, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", endMsg.Height))) // nolint: errcheck, gas
  50. }
  51. }
  52. if err != nil {
  53. fmt.Println("Failed to write message", err)
  54. os.Exit(1)
  55. }
  56. }
  57. }