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.

131 lines
4.7 KiB

  1. package types
  2. import (
  3. "fmt"
  4. "time"
  5. . "github.com/tendermint/tendermint/common"
  6. "github.com/tendermint/tendermint/wire"
  7. )
  8. // Functions to generate eventId strings
  9. func EventStringAccInput(addr []byte) string { return fmt.Sprintf("Acc/%X/Input", addr) }
  10. func EventStringAccOutput(addr []byte) string { return fmt.Sprintf("Acc/%X/Output", addr) }
  11. func EventStringAccCall(addr []byte) string { return fmt.Sprintf("Acc/%X/Call", addr) }
  12. func EventStringLogEvent(addr []byte) string { return fmt.Sprintf("Log/%X", addr) }
  13. func EventStringPermissions(name string) string { return fmt.Sprintf("Permissions/%s", name) }
  14. func EventStringNameReg(name string) string { return fmt.Sprintf("NameReg/%s", name) }
  15. func EventStringBond() string { return "Bond" }
  16. func EventStringUnbond() string { return "Unbond" }
  17. func EventStringRebond() string { return "Rebond" }
  18. func EventStringDupeout() string { return "Dupeout" }
  19. func EventStringNewBlock() string { return "NewBlock" }
  20. func EventStringFork() string { return "Fork" }
  21. func EventStringNewRound() string { return fmt.Sprintf("NewRound") }
  22. func EventStringTimeoutPropose() string { return fmt.Sprintf("TimeoutPropose") }
  23. func EventStringCompleteProposal() string { return fmt.Sprintf("CompleteProposal") }
  24. func EventStringPolka() string { return fmt.Sprintf("Polka") }
  25. func EventStringUnlock() string { return fmt.Sprintf("Unlock") }
  26. func EventStringLock() string { return fmt.Sprintf("Lock") }
  27. func EventStringRelock() string { return fmt.Sprintf("Relock") }
  28. func EventStringTimeoutWait() string { return fmt.Sprintf("TimeoutWait") }
  29. func EventStringVote() string { return fmt.Sprintf("Vote") }
  30. //----------------------------------------
  31. const (
  32. EventDataTypeNewBlock = byte(0x01)
  33. EventDataTypeFork = byte(0x02)
  34. EventDataTypeTx = byte(0x03)
  35. EventDataTypeCall = byte(0x04)
  36. EventDataTypeLog = byte(0x05)
  37. EventDataTypeRoundState = byte(0x11)
  38. EventDataTypeVote = byte(0x12)
  39. )
  40. type EventData interface {
  41. AssertIsEventData()
  42. }
  43. var _ = wire.RegisterInterface(
  44. struct{ EventData }{},
  45. wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
  46. // wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
  47. wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
  48. wire.ConcreteType{EventDataCall{}, EventDataTypeCall},
  49. wire.ConcreteType{EventDataLog{}, EventDataTypeLog},
  50. wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState},
  51. wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
  52. )
  53. // Most event messages are basic types (a block, a transaction)
  54. // but some (an input to a call tx or a receive) are more exotic
  55. type EventDataNewBlock struct {
  56. Block *Block `json:"block"`
  57. }
  58. // All txs fire EventDataTx, but only CallTx might have Return or Exception
  59. type EventDataTx struct {
  60. Tx Tx `json:"tx"`
  61. Return []byte `json:"return"`
  62. Exception string `json:"exception"`
  63. }
  64. // EventDataCall fires when we call a contract, and when a contract calls another contract
  65. type EventDataCall struct {
  66. CallData *CallData `json:"call_data"`
  67. Origin []byte `json:"origin"`
  68. TxID []byte `json:"tx_id"`
  69. Return []byte `json:"return"`
  70. Exception string `json:"exception"`
  71. }
  72. type CallData struct {
  73. Caller []byte `json:"caller"`
  74. Callee []byte `json:"callee"`
  75. Data []byte `json:"data"`
  76. Value int64 `json:"value"`
  77. Gas int64 `json:"gas"`
  78. }
  79. // EventDataLog fires when a contract executes the LOG opcode
  80. type EventDataLog struct {
  81. Address Word256 `json:"address"`
  82. Topics []Word256 `json:"topics"`
  83. Data []byte `json:"data"`
  84. Height int64 `json:"height"`
  85. }
  86. // We fire the most recent round state that led to the event
  87. // (ie. NewRound will have the previous rounds state)
  88. type EventDataRoundState struct {
  89. CurrentTime time.Time `json:"current_time"`
  90. Height int `json:"height"`
  91. Round int `json:"round"`
  92. Step string `json:"step"`
  93. StartTime time.Time `json:"start_time"`
  94. CommitTime time.Time `json:"commit_time"`
  95. Proposal *Proposal `json:"proposal"`
  96. ProposalBlock *Block `json:"proposal_block"`
  97. LockedRound int `json:"locked_round"`
  98. LockedBlock *Block `json:"locked_block"`
  99. POLRound int `json:"pol_round"`
  100. }
  101. type EventDataVote struct {
  102. Index int
  103. Address []byte
  104. Vote *Vote
  105. }
  106. func (_ EventDataNewBlock) AssertIsEventData() {}
  107. func (_ EventDataTx) AssertIsEventData() {}
  108. func (_ EventDataCall) AssertIsEventData() {}
  109. func (_ EventDataLog) AssertIsEventData() {}
  110. func (_ EventDataRoundState) AssertIsEventData() {}
  111. func (_ EventDataVote) AssertIsEventData() {}