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.0 KiB

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