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.

90 lines
3.0 KiB

  1. package types
  2. import (
  3. "fmt"
  4. . "github.com/tendermint/tendermint/common"
  5. "github.com/tendermint/tendermint/wire"
  6. )
  7. // Functions to generate eventId strings
  8. func EventStringAccInput(addr []byte) string { return fmt.Sprintf("Acc/%X/Input", addr) }
  9. func EventStringAccOutput(addr []byte) string { return fmt.Sprintf("Acc/%X/Output", addr) }
  10. func EventStringAccCall(addr []byte) string { return fmt.Sprintf("Acc/%X/Call", addr) }
  11. func EventStringLogEvent(addr []byte) string { return fmt.Sprintf("Log/%X", addr) }
  12. func EventStringPermissions(name string) string { return fmt.Sprintf("Permissions/%s", name) }
  13. func EventStringNameReg(name string) string { return fmt.Sprintf("NameReg/%s", name) }
  14. func EventStringBond() string { return "Bond" }
  15. func EventStringUnbond() string { return "Unbond" }
  16. func EventStringRebond() string { return "Rebond" }
  17. func EventStringDupeout() string { return "Dupeout" }
  18. func EventStringNewBlock() string { return "NewBlock" }
  19. func EventStringFork() string { return "Fork" }
  20. //----------------------------------------
  21. const (
  22. EventDataTypeNewBlock = byte(0x01)
  23. EventDataTypeFork = byte(0x02)
  24. EventDataTypeTx = byte(0x03)
  25. EventDataTypeCall = byte(0x04)
  26. EventDataTypeLog = byte(0x05)
  27. )
  28. type EventData interface {
  29. AssertIsEventData()
  30. }
  31. var _ = wire.RegisterInterface(
  32. struct{ EventData }{},
  33. wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
  34. // wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
  35. wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
  36. wire.ConcreteType{EventDataCall{}, EventDataTypeCall},
  37. wire.ConcreteType{EventDataLog{}, EventDataTypeLog},
  38. )
  39. // Most event messages are basic types (a block, a transaction)
  40. // but some (an input to a call tx or a receive) are more exotic:
  41. type EventDataNewBlock struct {
  42. Block *Block `json:"block"`
  43. }
  44. // All txs fire EventDataTx, but only CallTx might have Return or Exception
  45. type EventDataTx struct {
  46. Tx Tx `json:"tx"`
  47. Return []byte `json:"return"`
  48. Exception string `json:"exception"`
  49. }
  50. // EventDataCall fires when we call a contract, and when a contract calls another contract
  51. type EventDataCall struct {
  52. CallData *CallData `json:"call_data"`
  53. Origin []byte `json:"origin"`
  54. TxID []byte `json:"tx_id"`
  55. Return []byte `json:"return"`
  56. Exception string `json:"exception"`
  57. }
  58. type CallData struct {
  59. Caller []byte `json:"caller"`
  60. Callee []byte `json:"callee"`
  61. Data []byte `json:"data"`
  62. Value int64 `json:"value"`
  63. Gas int64 `json:"gas"`
  64. }
  65. // EventDataLog fires when a contract executes the LOG opcode
  66. type EventDataLog struct {
  67. Address Word256 `json:"address"`
  68. Topics []Word256 `json:"topics"`
  69. Data []byte `json:"data"`
  70. Height int64 `json:"height"`
  71. }
  72. func (_ EventDataNewBlock) AssertIsEventData() {}
  73. func (_ EventDataTx) AssertIsEventData() {}
  74. func (_ EventDataCall) AssertIsEventData() {}
  75. func (_ EventDataLog) AssertIsEventData() {}