-
Notifications
You must be signed in to change notification settings - Fork 175
/
events.go
64 lines (53 loc) · 1.17 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
package generator
import (
"fmt"
"github.com/onflow/cadence"
encoding "github.com/onflow/cadence/encoding/json"
"github.com/onflow/flow-go/model/flow"
)
type Events struct {
count uint32
ids *Identifiers
}
func EventGenerator() *Events {
return &Events{
count: 1,
ids: IdentifierGenerator(),
}
}
func (g *Events) New() flow.Event {
identifier := fmt.Sprintf("FooEvent%d", g.count)
typeID := "test." + identifier
testEventType := &cadence.EventType{
TypeID: typeID,
Identifier: identifier,
Fields: []cadence.Field{
{
Identifier: "a",
Type: cadence.IntType{},
},
{
Identifier: "b",
Type: cadence.StringType{},
},
},
}
testEvent := cadence.NewEvent(
[]cadence.Value{
cadence.NewInt(int(g.count)),
cadence.NewString("foo"),
}).WithType(testEventType)
payload, err := encoding.Encode(testEvent)
if err != nil {
panic(fmt.Sprintf("unexpected error while encoding events: %s", err))
}
event := flow.Event{
Type: flow.EventType(typeID),
TransactionID: g.ids.New(),
TransactionIndex: g.count,
EventIndex: g.count,
Payload: payload,
}
g.count++
return event
}