-
Notifications
You must be signed in to change notification settings - Fork 178
/
event.go
55 lines (44 loc) · 1.22 KB
/
event.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
package models
import (
"github.com/onflow/flow-go/engine/access/rest/util"
"github.com/onflow/flow-go/model/flow"
)
func (e *Event) Build(event flow.Event) {
e.Type_ = string(event.Type)
e.TransactionId = event.TransactionID.String()
e.TransactionIndex = util.FromUint64(uint64(event.TransactionIndex))
e.EventIndex = util.FromUint64(uint64(event.EventIndex))
e.Payload = util.ToBase64(event.Payload)
}
type Events []Event
func (e *Events) Build(events []flow.Event) {
evs := make([]Event, len(events))
for i, ev := range events {
var event Event
event.Build(ev)
evs[i] = event
}
*e = evs
}
func (b *BlockEvents) Build(blockEvents flow.BlockEvents) {
b.BlockHeight = util.FromUint64(blockEvents.BlockHeight)
b.BlockId = blockEvents.BlockID.String()
b.BlockTimestamp = blockEvents.BlockTimestamp
var events Events
events.Build(blockEvents.Events)
b.Events = events
}
type BlocksEvents []BlockEvents
func (b *BlocksEvents) Build(blocksEvents []flow.BlockEvents) {
evs := make([]BlockEvents, 0)
for _, ev := range blocksEvents {
// don't include blocks without events
if len(ev.Events) == 0 {
continue
}
var blockEvent BlockEvents
blockEvent.Build(ev)
evs = append(evs, blockEvent)
}
*b = evs
}