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.

102 lines
3.2 KiB

  1. package types
  2. import (
  3. "time"
  4. "github.com/tendermint/go-wire"
  5. )
  6. // Functions to generate eventId strings
  7. // Reserved
  8. func EventStringBond() string { return "Bond" }
  9. func EventStringUnbond() string { return "Unbond" }
  10. func EventStringRebond() string { return "Rebond" }
  11. func EventStringDupeout() string { return "Dupeout" }
  12. func EventStringFork() string { return "Fork" }
  13. func EventStringNewBlock() string { return "NewBlock" }
  14. func EventStringNewRound() string { return "NewRound" }
  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. // We fire the most recent round state that led to the event
  61. // (ie. NewRound will have the previous rounds state)
  62. type EventDataRoundState struct {
  63. CurrentTime time.Time `json:"current_time"`
  64. Height int `json:"height"`
  65. Round int `json:"round"`
  66. Step string `json:"step"`
  67. StartTime time.Time `json:"start_time"`
  68. CommitTime time.Time `json:"commit_time"`
  69. Proposal *Proposal `json:"proposal"`
  70. ProposalBlock *Block `json:"proposal_block"`
  71. LockedRound int `json:"locked_round"`
  72. LockedBlock *Block `json:"locked_block"`
  73. POLRound int `json:"pol_round"`
  74. }
  75. type EventDataVote struct {
  76. Index int
  77. Address []byte
  78. Vote *Vote
  79. }
  80. func (_ EventDataNewBlock) AssertIsEventData() {}
  81. func (_ EventDataTx) AssertIsEventData() {}
  82. func (_ EventDataApp) AssertIsEventData() {}
  83. func (_ EventDataRoundState) AssertIsEventData() {}
  84. func (_ EventDataVote) AssertIsEventData() {}