Skip to content

Commit 80d60fc

Browse files
peterarguej pimmel
andauthored
Add support for ProtocolStateVersionUpgrade service event (#74)
* Add support for ProtocolStateVersionUpgrade service event * Use generic service event parser --------- Co-authored-by: j pimmel <frankly.watson@gmail.com>
1 parent 5dbd254 commit 80d60fc

File tree

1 file changed

+5
-75
lines changed

1 file changed

+5
-75
lines changed

state/convert.go

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package state
22

33
import (
44
"bytes"
5-
"encoding/json"
65
"fmt"
76
"strings"
87
"time"
@@ -46,84 +45,15 @@ func convertExecutionResult(hash []byte, height uint64, result *entities.Executi
4645
}
4746
for _, ev := range result.ServiceEvents {
4847
eventType := flow.ServiceEventType(ev.Type)
49-
switch eventType {
50-
case flow.ServiceEventSetup:
51-
setup := &flow.EpochSetup{}
52-
err := json.Unmarshal(ev.Payload, setup)
53-
if err != nil {
54-
log.Errorf(
55-
"Failed to decode %q service event in block %x at height %d: %s",
56-
ev.Type, hash, height, err,
57-
)
58-
return flowExecutionResult{}, false
59-
}
60-
exec.ServiceEvents = append(exec.ServiceEvents, flow.ServiceEvent{
61-
Event: setup,
62-
Type: eventType,
63-
})
64-
case flow.ServiceEventCommit:
65-
commit := &flow.EpochCommit{}
66-
err := json.Unmarshal(ev.Payload, commit)
67-
if err != nil {
68-
log.Errorf(
69-
"Failed to decode %q service event in block %x at height %d: %s",
70-
ev.Type, hash, height, err,
71-
)
72-
return flowExecutionResult{}, false
73-
}
74-
exec.ServiceEvents = append(exec.ServiceEvents, flow.ServiceEvent{
75-
Event: commit,
76-
Type: eventType,
77-
})
78-
case flow.ServiceEventVersionBeacon:
79-
beacon := &flow.VersionBeacon{}
80-
err := json.Unmarshal(ev.Payload, beacon)
81-
if err != nil {
82-
log.Errorf(
83-
"Failed to decode %q service event in block %x at height %d: %s",
84-
ev.Type, hash, height, err,
85-
)
86-
return flowExecutionResult{}, false
87-
}
88-
exec.ServiceEvents = append(exec.ServiceEvents, flow.ServiceEvent{
89-
Event: beacon,
90-
Type: eventType,
91-
})
92-
case flow.ServiceEventProtocolStateVersionUpgrade:
93-
event := &flow.ProtocolStateVersionUpgrade{}
94-
err := json.Unmarshal(ev.Payload, event)
95-
if err != nil {
96-
log.Errorf(
97-
"Failed to decode %q service event in block %x at height %d: %s",
98-
ev.Type, hash, height, err,
99-
)
100-
return flowExecutionResult{}, false
101-
}
102-
exec.ServiceEvents = append(exec.ServiceEvents, flow.ServiceEvent{
103-
Event: event,
104-
Type: eventType,
105-
})
106-
case flow.ServiceEventRecover:
107-
event := &flow.EpochRecover{}
108-
err := json.Unmarshal(ev.Payload, event)
109-
if err != nil {
110-
log.Errorf(
111-
"Failed to decode %q service event in block %x at height %d: %s",
112-
ev.Type, hash, height, err,
113-
)
114-
return flowExecutionResult{}, false
115-
}
116-
exec.ServiceEvents = append(exec.ServiceEvents, flow.ServiceEvent{
117-
Event: event,
118-
Type: eventType,
119-
})
120-
default:
48+
serviceEvent, err := flow.ServiceEventJSONMarshaller.UnmarshalWithType(ev.Payload, eventType)
49+
if err != nil {
12150
log.Errorf(
122-
"Unknown service event type in block %x at height %d: %q",
123-
hash, height, ev.Type,
51+
"Failed to decode %q service event in block %x at height %d: %s",
52+
ev.Type, hash, height, err,
12453
)
12554
return flowExecutionResult{}, false
12655
}
56+
exec.ServiceEvents = append(exec.ServiceEvents, serviceEvent)
12757
}
12858
return exec, true
12959
}

0 commit comments

Comments
 (0)