forked from hyperledger-archives/burrow
/
events.go
154 lines (131 loc) · 5.73 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2017 Monax Industries Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package txs
import (
"fmt"
"time"
. "github.com/hyperledger/burrow/word256"
"github.com/tendermint/go-wire"
tm_types "github.com/tendermint/tendermint/types" // Block
)
// Functions to generate eventId strings
func EventStringAccInput(addr []byte) string { return fmt.Sprintf("Acc/%X/Input", addr) }
func EventStringAccOutput(addr []byte) string { return fmt.Sprintf("Acc/%X/Output", addr) }
func EventStringAccCall(addr []byte) string { return fmt.Sprintf("Acc/%X/Call", addr) }
func EventStringLogEvent(addr []byte) string { return fmt.Sprintf("Log/%X", addr) }
func EventStringPermissions(name string) string { return fmt.Sprintf("Permissions/%s", name) }
func EventStringNameReg(name string) string { return fmt.Sprintf("NameReg/%s", name) }
func EventStringBond() string { return "Bond" }
func EventStringUnbond() string { return "Unbond" }
func EventStringRebond() string { return "Rebond" }
func EventStringDupeout() string { return "Dupeout" }
func EventStringNewBlock() string { return "NewBlock" }
func EventStringFork() string { return "Fork" }
func EventStringNewRound() string { return fmt.Sprintf("NewRound") }
func EventStringTimeoutPropose() string { return fmt.Sprintf("TimeoutPropose") }
func EventStringCompleteProposal() string { return fmt.Sprintf("CompleteProposal") }
func EventStringPolka() string { return fmt.Sprintf("Polka") }
func EventStringUnlock() string { return fmt.Sprintf("Unlock") }
func EventStringLock() string { return fmt.Sprintf("Lock") }
func EventStringRelock() string { return fmt.Sprintf("Relock") }
func EventStringTimeoutWait() string { return fmt.Sprintf("TimeoutWait") }
func EventStringVote() string { return fmt.Sprintf("Vote") }
//----------------------------------------
const (
EventDataTypeNewBlock = byte(0x01)
EventDataTypeFork = byte(0x02)
EventDataTypeTx = byte(0x03)
EventDataTypeCall = byte(0x04)
EventDataTypeLog = byte(0x05)
EventDataTypeNewBlockHeader = byte(0x06)
EventDataTypeRoundState = byte(0x11)
EventDataTypeVote = byte(0x12)
)
type EventData interface {
AssertIsEventData()
}
var _ = wire.RegisterInterface(
struct{ EventData }{},
wire.ConcreteType{EventDataNewBlockHeader{}, EventDataTypeNewBlockHeader},
wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
// wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
wire.ConcreteType{EventDataCall{}, EventDataTypeCall},
wire.ConcreteType{EventDataLog{}, EventDataTypeLog},
wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState},
wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
)
// Most event messages are basic types (a block, a transaction)
// but some (an input to a call tx or a receive) are more exotic
type EventDataNewBlock struct {
Block *tm_types.Block `json:"block"`
}
type EventDataNewBlockHeader struct {
Header *tm_types.Header `json:"header"`
}
// All txs fire EventDataTx, but only CallTx might have Return or Exception
type EventDataTx struct {
Tx Tx `json:"tx"`
Return []byte `json:"return"`
Exception string `json:"exception"`
}
// EventDataCall fires when we call a contract, and when a contract calls another contract
type EventDataCall struct {
CallData *CallData `json:"call_data"`
Origin []byte `json:"origin"`
TxID []byte `json:"tx_id"`
Return []byte `json:"return"`
Exception string `json:"exception"`
}
type CallData struct {
Caller []byte `json:"caller"`
Callee []byte `json:"callee"`
Data []byte `json:"data"`
Value int64 `json:"value"`
Gas int64 `json:"gas"`
}
// EventDataLog fires when a contract executes the LOG opcode
type EventDataLog struct {
Address Word256 `json:"address"`
Topics []Word256 `json:"topics"`
Data []byte `json:"data"`
Height int64 `json:"height"`
}
// We fire the most recent round state that led to the event
// (ie. NewRound will have the previous rounds state)
type EventDataRoundState struct {
CurrentTime time.Time `json:"current_time"`
Height int `json:"height"`
Round int `json:"round"`
Step string `json:"step"`
StartTime time.Time `json:"start_time"`
CommitTime time.Time `json:"commit_time"`
Proposal *tm_types.Proposal `json:"proposal"`
ProposalBlock *tm_types.Block `json:"proposal_block"`
LockedRound int `json:"locked_round"`
LockedBlock *tm_types.Block `json:"locked_block"`
POLRound int `json:"pol_round"`
}
type EventDataVote struct {
Index int
Address []byte
Vote *tm_types.Vote
}
func (_ EventDataNewBlock) AssertIsEventData() {}
func (_ EventDataNewBlockHeader) AssertIsEventData() {}
func (_ EventDataTx) AssertIsEventData() {}
func (_ EventDataCall) AssertIsEventData() {}
func (_ EventDataLog) AssertIsEventData() {}
func (_ EventDataRoundState) AssertIsEventData() {}
func (_ EventDataVote) AssertIsEventData() {}