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
77 lines (66 loc) · 1.83 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
package exec
import (
"fmt"
"reflect"
"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() []*StreamEvent {
var ses []*StreamEvent
ses = append(ses, &StreamEvent{
BeginBlock: &BeginBlock{
Height: be.Height,
PredecessorHeight: be.PredecessorHeight,
NumTxs: uint64(len(be.TxExecutions)),
Header: be.Header,
},
})
for _, txe := range be.TxExecutions {
ses = append(ses, txe.StreamEvents()...)
}
return append(ses, &StreamEvent{
EndBlock: &EndBlock{
Height: be.Height,
},
})
}
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
func (be *BlockExecution) Get(key string) (interface{}, bool) {
switch key {
case event.EventIDKey:
return EventStringBlockExecution(be.Height), true
case event.EventTypeKey:
return be.EventType(), true
}
v, ok := query.GetReflect(reflect.ValueOf(be.Header), key)
if ok {
return v, true
}
return query.GetReflect(reflect.ValueOf(be), key)
}
func QueryForBlockExecutionFromHeight(height uint64) *query.Builder {
return QueryForBlockExecution().AndGreaterThanOrEqual(event.HeightKey, height)
}
func QueryForBlockExecution() *query.Builder {
return query.NewBuilder().AndEquals(event.EventTypeKey, TypeBlockExecution)
}