This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
block_execution.go
122 lines (107 loc) · 2.79 KB
/
block_execution.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
package exec
import (
"fmt"
"github.com/hyperledger/burrow/event"
"github.com/hyperledger/burrow/event/query"
"github.com/hyperledger/burrow/txs"
)
func EventStringBlockExecution(height uint64) string { return fmt.Sprintf("Execution/Block/%v", height) }
// Write out TxExecutions parenthetically
func (be *BlockExecution) StreamEvents() StreamEvents {
var ses StreamEvents
ses = append(ses, &StreamEvent{
BeginBlock: &BeginBlock{
Height: be.Height,
Header: be.Header,
},
})
for _, txe := range be.TxExecutions {
ses = append(ses, txe.StreamEvents()...)
}
return append(ses, &StreamEvent{
EndBlock: &EndBlock{
Height: be.Height,
},
})
}
func (be *BlockExecution) EncodeHeader() ([]byte, error) {
return cdc.MarshalBinaryBare(be.Header)
}
func (*BlockExecution) EventType() EventType {
return TypeBlockExecution
}
func (be *BlockExecution) Tx(txEnv *txs.Envelope) *TxExecution {
txe := NewTxExecution(txEnv)
be.AppendTxs(txe)
return txe
}
func (be *BlockExecution) AppendTxs(tail ...*TxExecution) {
for i, txe := range tail {
txe.Index = uint64(len(be.TxExecutions) + i)
txe.Height = be.Height
}
be.TxExecutions = append(be.TxExecutions, tail...)
}
// Tags
type TaggedBlockExecution struct {
query.Tagged
*BlockExecution
}
func (be *BlockExecution) Tagged() *TaggedBlockExecution {
return &TaggedBlockExecution{
Tagged: query.MergeTags(
query.TagMap{
event.EventIDKey: EventStringBlockExecution(be.Height),
event.EventTypeKey: be.EventType(),
},
query.MustReflectTags(be),
query.MustReflectTags(be.Header),
),
BlockExecution: be,
}
}
func QueryForBlockExecutionFromHeight(height uint64) *query.Builder {
return QueryForBlockExecution().AndGreaterThanOrEqual(event.HeightKey, height)
}
func QueryForBlockExecution() *query.Builder {
return query.NewBuilder().AndEquals(event.EventTypeKey, TypeBlockExecution)
}
type TaggedBlockEvent struct {
query.Tagged
*StreamEvent
}
func (ev *StreamEvent) EventType() EventType {
switch {
case ev.BeginBlock != nil:
return TypeBeginBlock
case ev.BeginTx != nil:
return TypeBeginTx
case ev.Envelope != nil:
return TypeEnvelope
case ev.Event != nil:
return ev.Event.EventType()
case ev.EndTx != nil:
return TypeEndTx
case ev.EndBlock != nil:
return TypeEndBlock
}
return TypeUnknown
}
func (ev *StreamEvent) Tagged() *TaggedBlockEvent {
return &TaggedBlockEvent{
Tagged: query.MergeTags(
query.TagMap{
event.EventTypeKey: ev.EventType(),
},
query.MustReflectTags(ev.BeginBlock, "Height"),
query.MustReflectTags(ev.BeginBlock.GetHeader()),
query.MustReflectTags(ev.BeginTx),
query.MustReflectTags(ev.BeginTx.GetTxHeader()),
ev.Envelope.Tagged(),
ev.Event.Tagged(),
query.MustReflectTags(ev.EndTx),
query.MustReflectTags(ev.EndBlock, "Height"),
),
StreamEvent: ev,
}
}