tendermint/types/events.go

98 lines
3.0 KiB
Go
Raw Normal View History

2015-04-13 18:26:41 -07:00
package types
import (
2016-01-13 15:38:55 -08:00
// for registering TMEventData as events.EventData
2016-01-12 13:54:27 -08:00
"github.com/tendermint/go-events"
"github.com/tendermint/go-wire"
2015-04-13 18:26:41 -07:00
)
2015-04-15 19:14:08 -07:00
// Functions to generate eventId strings
2015-12-01 20:12:01 -08:00
// Reserved
func EventStringBond() string { return "Bond" }
func EventStringUnbond() string { return "Unbond" }
func EventStringRebond() string { return "Rebond" }
func EventStringDupeout() string { return "Dupeout" }
func EventStringFork() string { return "Fork" }
func EventStringNewBlock() string { return "NewBlock" }
func EventStringNewRound() string { return "NewRound" }
func EventStringNewRoundStep() string { return "NewRoundStep" }
2015-12-01 20:12:01 -08:00
func EventStringTimeoutPropose() string { return "TimeoutPropose" }
func EventStringCompleteProposal() string { return "CompleteProposal" }
func EventStringPolka() string { return "Polka" }
func EventStringUnlock() string { return "Unlock" }
func EventStringLock() string { return "Lock" }
func EventStringRelock() string { return "Relock" }
func EventStringTimeoutWait() string { return "TimeoutWait" }
func EventStringVote() string { return "Vote" }
func EventStringApp() string { return "App" }
2015-09-09 13:45:53 -07:00
//----------------------------------------
2016-01-13 15:38:55 -08:00
// implements events.EventData
type TMEventData interface {
events.EventData
// AssertIsTMEventData()
}
const (
EventDataTypeNewBlock = byte(0x01)
EventDataTypeFork = byte(0x02)
EventDataTypeTx = byte(0x03)
2015-12-01 20:12:01 -08:00
EventDataTypeApp = byte(0x04) // Custom app event
2015-09-09 13:45:53 -07:00
EventDataTypeRoundState = byte(0x11)
EventDataTypeVote = byte(0x12)
)
var _ = wire.RegisterInterface(
2016-01-13 15:38:55 -08:00
struct{ TMEventData }{},
wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
// wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
2015-12-01 20:12:01 -08:00
wire.ConcreteType{EventDataApp{}, EventDataTypeApp},
2015-12-22 12:23:22 -08:00
wire.ConcreteType{&EventDataRoundState{}, EventDataTypeRoundState}, // a pointer because we use it internally
2015-09-09 13:45:53 -07:00
wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
)
2015-04-15 19:14:08 -07:00
// Most event messages are basic types (a block, a transaction)
2015-09-09 13:45:53 -07:00
// but some (an input to a call tx or a receive) are more exotic
2015-04-15 19:14:08 -07:00
type EventDataNewBlock struct {
Block *Block `json:"block"`
}
2015-12-01 20:12:01 -08:00
// All txs fire EventDataTx
type EventDataTx struct {
2015-05-01 17:26:49 -07:00
Tx Tx `json:"tx"`
Return []byte `json:"return"`
Exception string `json:"exception"`
2015-04-15 19:14:08 -07:00
}
2015-12-01 20:12:01 -08:00
type EventDataApp struct {
Key string `json:"key"`
Data []byte `json:"bytes"`
2015-04-15 19:14:08 -07:00
}
2015-09-09 13:45:53 -07:00
type EventDataRoundState struct {
Height int `json:"height"`
Round int `json:"round"`
Step string `json:"step"`
// private, not exposed to websockets
RoundState interface{} `json:"-"`
2015-09-09 13:45:53 -07:00
}
type EventDataVote struct {
Index int
Address []byte
Vote *Vote
}
2016-01-13 15:38:55 -08:00
func (_ EventDataNewBlock) AssertIsTMEventData() {}
func (_ EventDataTx) AssertIsTMEventData() {}
func (_ EventDataApp) AssertIsTMEventData() {}
func (_ EventDataRoundState) AssertIsTMEventData() {}
func (_ EventDataVote) AssertIsTMEventData() {}