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.

97 lines
3.0 KiB

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