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
85 lines (70 loc) · 1.95 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
package exec
import (
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/hyperledger/burrow/event"
"github.com/hyperledger/burrow/event/query"
"github.com/hyperledger/burrow/txs"
abciTypes "github.com/tendermint/tendermint/abci/types"
)
func EventStringBlockExecution(height uint64) string { return fmt.Sprintf("Execution/Block/%v", height) }
func DecodeBlockExecution(bs []byte) (*BlockExecution, error) {
be := new(BlockExecution)
err := cdc.UnmarshalBinary(bs, be)
if err != nil {
return nil, err
}
return be, nil
}
func (be *BlockExecution) Encode() ([]byte, error) {
return cdc.MarshalBinary(be)
}
func (*BlockExecution) EventType() EventType {
return TypeBlockExecution
}
func (be *BlockExecution) Tx(txEnv *txs.Envelope) *TxExecution {
txe := NewTxExecution(txEnv)
be.Append(txe)
return txe
}
func (be *BlockExecution) Append(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.BlockHeader),
),
BlockExecution: be,
}
}
type ABCIHeader struct {
*abciTypes.Header
}
// Gogo proto support
func (h *ABCIHeader) Marshal() ([]byte, error) {
return proto.Marshal(h.Header)
}
func (h *ABCIHeader) Unmarshal(data []byte) error {
return proto.Unmarshal(data, h.Header)
}
func QueryForBlockExecutionFromHeight(height uint64) *query.Builder {
return QueryForBlockExecution().AndGreaterThanOrEqual(event.HeightKey, height)
}
func QueryForBlockExecution() *query.Builder {
return query.NewBuilder().AndEquals(event.EventTypeKey, TypeBlockExecution)
}