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.

78 lines
1.7 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
  1. /*
  2. json2wal converts JSON file to binary WAL file.
  3. Usage:
  4. json2wal <path-to-JSON> <path-to-wal>
  5. */
  6. package main
  7. import (
  8. "bufio"
  9. "fmt"
  10. "io"
  11. "os"
  12. "strings"
  13. amino "github.com/tendermint/go-amino"
  14. cs "github.com/tendermint/tendermint/consensus"
  15. "github.com/tendermint/tendermint/types"
  16. )
  17. var cdc = amino.NewCodec()
  18. func init() {
  19. cs.RegisterMessages(cdc)
  20. cs.RegisterWALMessages(cdc)
  21. types.RegisterBlockAmino(cdc)
  22. }
  23. func main() {
  24. if len(os.Args) < 3 {
  25. fmt.Fprintln(os.Stderr, "missing arguments: Usage:json2wal <path-to-JSON> <path-to-wal>")
  26. os.Exit(1)
  27. }
  28. f, err := os.Open(os.Args[1])
  29. if err != nil {
  30. panic(fmt.Errorf("failed to open WAL file: %v", err))
  31. }
  32. defer f.Close()
  33. walFile, err := os.OpenFile(os.Args[2], os.O_EXCL|os.O_WRONLY|os.O_CREATE, 0666)
  34. if err != nil {
  35. panic(fmt.Errorf("failed to open WAL file: %v", err))
  36. }
  37. defer walFile.Close()
  38. // the length of tendermint/wal/MsgInfo in the wal.json may exceed the defaultBufSize(4096) of bufio
  39. // because of the byte array in BlockPart
  40. // leading to unmarshal error: unexpected end of JSON input
  41. br := bufio.NewReaderSize(f, 2*types.BlockPartSizeBytes)
  42. dec := cs.NewWALEncoder(walFile)
  43. for {
  44. msgJSON, _, err := br.ReadLine()
  45. if err == io.EOF {
  46. break
  47. } else if err != nil {
  48. panic(fmt.Errorf("failed to read file: %v", err))
  49. }
  50. // ignore the ENDHEIGHT in json.File
  51. if strings.HasPrefix(string(msgJSON), "ENDHEIGHT") {
  52. continue
  53. }
  54. var msg cs.TimedWALMessage
  55. err = cdc.UnmarshalJSON(msgJSON, &msg)
  56. if err != nil {
  57. panic(fmt.Errorf("failed to unmarshal json: %v", err))
  58. }
  59. err = dec.Encode(&msg)
  60. if err != nil {
  61. panic(fmt.Errorf("failed to encode msg: %v", err))
  62. }
  63. }
  64. }