github.com/koko1123/flow-go-1@v0.29.6/admin/commands/state_synchronization/read_execution_data.go (about) 1 package state_synchronization 2 3 import ( 4 "context" 5 "encoding/hex" 6 "fmt" 7 8 "github.com/koko1123/flow-go-1/admin" 9 "github.com/koko1123/flow-go-1/admin/commands" 10 "github.com/koko1123/flow-go-1/model/flow" 11 "github.com/koko1123/flow-go-1/module/executiondatasync/execution_data" 12 ) 13 14 var _ commands.AdminCommand = (*ReadExecutionDataCommand)(nil) 15 16 type requestData struct { 17 rootID flow.Identifier 18 } 19 20 type ReadExecutionDataCommand struct { 21 executionDataStore execution_data.ExecutionDataStore 22 } 23 24 func (r *ReadExecutionDataCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) { 25 data := req.ValidatorData.(*requestData) 26 27 ed, err := r.executionDataStore.GetExecutionData(ctx, data.rootID) 28 29 if err != nil { 30 return nil, fmt.Errorf("failed to get execution data: %w", err) 31 } 32 33 return commands.ConvertToMap(ed) 34 } 35 36 // Validator validates the request. 37 // Returns admin.InvalidAdminReqError for invalid/malformed requests. 38 func (r *ReadExecutionDataCommand) Validator(req *admin.CommandRequest) error { 39 input, ok := req.Data.(map[string]interface{}) 40 if !ok { 41 return admin.NewInvalidAdminReqFormatError("expected map[string]any") 42 } 43 44 id, ok := input["execution_data_id"] 45 if !ok { 46 return admin.NewInvalidAdminReqErrorf("missing required field 'execution_data_id") 47 } 48 49 data := &requestData{} 50 51 idStr, ok := id.(string) 52 if !ok { 53 return admin.NewInvalidAdminReqParameterError("execution_data_id", "must be a string", id) 54 } 55 56 if len(idStr) == 2*flow.IdentifierLen { 57 b, err := hex.DecodeString(idStr) 58 if err != nil { 59 return admin.NewInvalidAdminReqParameterError("execution_data_id", "must be 64-char hex string", id) 60 } 61 data.rootID = flow.HashToID(b) 62 } else { 63 return admin.NewInvalidAdminReqParameterError("execution_data_id", "must be 64-char hex string", id) 64 } 65 66 req.ValidatorData = data 67 68 return nil 69 } 70 71 func NewReadExecutionDataCommand(store execution_data.ExecutionDataStore) commands.AdminCommand { 72 return &ReadExecutionDataCommand{ 73 store, 74 } 75 }