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.

101 lines
3.2 KiB

  1. package types
  2. import (
  3. // for registering TMEventData as events.EventData
  4. . "github.com/tendermint/go-common"
  5. "github.com/tendermint/go-events"
  6. "github.com/tendermint/go-wire"
  7. )
  8. // Functions to generate eventId strings
  9. // Reserved
  10. func EventStringBond() string { return "Bond" }
  11. func EventStringUnbond() string { return "Unbond" }
  12. func EventStringRebond() string { return "Rebond" }
  13. func EventStringDupeout() string { return "Dupeout" }
  14. func EventStringFork() string { return "Fork" }
  15. func EventStringTx(tx Tx) string { return Fmt("Tx:%X", tx.Hash()) }
  16. func EventStringNewBlock() string { return "NewBlock" }
  17. func EventStringNewBlockHeader() string { return "NewBlockHeader" }
  18. func EventStringNewRound() string { return "NewRound" }
  19. func EventStringNewRoundStep() string { return "NewRoundStep" }
  20. func EventStringTimeoutPropose() string { return "TimeoutPropose" }
  21. func EventStringCompleteProposal() string { return "CompleteProposal" }
  22. func EventStringPolka() string { return "Polka" }
  23. func EventStringUnlock() string { return "Unlock" }
  24. func EventStringLock() string { return "Lock" }
  25. func EventStringRelock() string { return "Relock" }
  26. func EventStringTimeoutWait() string { return "TimeoutWait" }
  27. func EventStringVote() string { return "Vote" }
  28. //----------------------------------------
  29. // implements events.EventData
  30. type TMEventData interface {
  31. events.EventData
  32. // AssertIsTMEventData()
  33. }
  34. const (
  35. EventDataTypeNewBlock = byte(0x01)
  36. EventDataTypeFork = byte(0x02)
  37. EventDataTypeTx = byte(0x03)
  38. EventDataTypeNewBlockHeader = byte(0x04)
  39. EventDataTypeRoundState = byte(0x11)
  40. EventDataTypeVote = byte(0x12)
  41. )
  42. var _ = wire.RegisterInterface(
  43. struct{ TMEventData }{},
  44. wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
  45. wire.ConcreteType{EventDataNewBlockHeader{}, EventDataTypeNewBlockHeader},
  46. // wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
  47. wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
  48. wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState},
  49. wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
  50. )
  51. // Most event messages are basic types (a block, a transaction)
  52. // but some (an input to a call tx or a receive) are more exotic
  53. type EventDataNewBlock struct {
  54. Block *Block `json:"block"`
  55. }
  56. // light weight event for benchmarking
  57. type EventDataNewBlockHeader struct {
  58. Header *Header `json:"header"`
  59. }
  60. // All txs fire EventDataTx
  61. type EventDataTx struct {
  62. Tx Tx `json:"tx"`
  63. Result []byte `json:"result"`
  64. Log string `json:"log"`
  65. Error string `json:"error"`
  66. }
  67. // NOTE: This goes into the replay WAL
  68. type EventDataRoundState struct {
  69. Height int `json:"height"`
  70. Round int `json:"round"`
  71. Step string `json:"step"`
  72. // private, not exposed to websockets
  73. RoundState interface{} `json:"-"`
  74. }
  75. type EventDataVote struct {
  76. Index int
  77. Address []byte
  78. Vote *Vote
  79. }
  80. func (_ EventDataNewBlock) AssertIsTMEventData() {}
  81. func (_ EventDataNewBlockHeader) AssertIsTMEventData() {}
  82. func (_ EventDataTx) AssertIsTMEventData() {}
  83. func (_ EventDataRoundState) AssertIsTMEventData() {}
  84. func (_ EventDataVote) AssertIsTMEventData() {}