-
Notifications
You must be signed in to change notification settings - Fork 179
/
read_execution_data.go
76 lines (58 loc) · 1.63 KB
/
read_execution_data.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
package state_synchronization
import (
"context"
"encoding/hex"
"errors"
"fmt"
"github.com/onflow/flow-go/admin"
"github.com/onflow/flow-go/admin/commands"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/state_synchronization"
)
var _ commands.AdminCommand = (*ReadExecutionDataCommand)(nil)
type requestData struct {
rootID flow.Identifier
}
type ReadExecutionDataCommand struct {
eds state_synchronization.ExecutionDataService
}
func (r *ReadExecutionDataCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) {
data := req.ValidatorData.(*requestData)
ed, err := r.eds.Get(ctx, data.rootID)
if err != nil {
return nil, fmt.Errorf("failed to get execution data: %w", err)
}
return commands.ConvertToMap(ed)
}
func (r *ReadExecutionDataCommand) Validator(req *admin.CommandRequest) error {
input, ok := req.Data.(map[string]interface{})
if !ok {
return errors.New("wrong input format")
}
id, ok := input["execution_data_id"]
if !ok {
return errors.New("the \"execution_data_id\" field is required")
}
errInvalidIDValue := fmt.Errorf("invalid value for \"execution_data_id\": %v", id)
data := &requestData{}
idStr, ok := id.(string)
if !ok {
return errInvalidIDValue
}
if len(idStr) == 2*flow.IdentifierLen {
b, err := hex.DecodeString(idStr)
if err != nil {
return errInvalidIDValue
}
data.rootID = flow.HashToID(b)
} else {
return errInvalidIDValue
}
req.ValidatorData = data
return nil
}
func NewReadExecutionDataCommand(eds state_synchronization.ExecutionDataService) commands.AdminCommand {
return &ReadExecutionDataCommand{
eds,
}
}