-
Notifications
You must be signed in to change notification settings - Fork 179
/
read_execution_data.go
75 lines (58 loc) · 1.93 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
package state_synchronization
import (
"context"
"encoding/hex"
"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/executiondatasync/execution_data"
)
var _ commands.AdminCommand = (*ReadExecutionDataCommand)(nil)
type requestData struct {
rootID flow.Identifier
}
type ReadExecutionDataCommand struct {
executionDataStore execution_data.ExecutionDataStore
}
func (r *ReadExecutionDataCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) {
data := req.ValidatorData.(*requestData)
ed, err := r.executionDataStore.Get(ctx, data.rootID)
if err != nil {
return nil, fmt.Errorf("failed to get execution data: %w", err)
}
return commands.ConvertToMap(ed)
}
// Validator validates the request.
// Returns admin.InvalidAdminReqError for invalid/malformed requests.
func (r *ReadExecutionDataCommand) Validator(req *admin.CommandRequest) error {
input, ok := req.Data.(map[string]interface{})
if !ok {
return admin.NewInvalidAdminReqFormatError("expected map[string]any")
}
id, ok := input["execution_data_id"]
if !ok {
return admin.NewInvalidAdminReqErrorf("missing required field 'execution_data_id")
}
data := &requestData{}
idStr, ok := id.(string)
if !ok {
return admin.NewInvalidAdminReqParameterError("execution_data_id", "must be a string", id)
}
if len(idStr) == 2*flow.IdentifierLen {
b, err := hex.DecodeString(idStr)
if err != nil {
return admin.NewInvalidAdminReqParameterError("execution_data_id", "must be 64-char hex string", id)
}
data.rootID = flow.HashToID(b)
} else {
return admin.NewInvalidAdminReqParameterError("execution_data_id", "must be 64-char hex string", id)
}
req.ValidatorData = data
return nil
}
func NewReadExecutionDataCommand(store execution_data.ExecutionDataStore) commands.AdminCommand {
return &ReadExecutionDataCommand{
store,
}
}