github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/execution_result.go (about) 1 package rest 2 3 import ( 4 "fmt" 5 6 "github.com/koko1123/flow-go-1/access" 7 "github.com/koko1123/flow-go-1/engine/access/rest/models" 8 "github.com/koko1123/flow-go-1/engine/access/rest/request" 9 ) 10 11 // GetExecutionResultsByBlockIDs gets Execution Result payload by block IDs. 12 func GetExecutionResultsByBlockIDs(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) { 13 req, err := r.GetExecutionResultByBlockIDsRequest() 14 if err != nil { 15 return nil, NewBadRequestError(err) 16 } 17 18 // for each block ID we retrieve execution result 19 results := make([]models.ExecutionResult, len(req.BlockIDs)) 20 for i, id := range req.BlockIDs { 21 res, err := backend.GetExecutionResultForBlockID(r.Context(), id) 22 if err != nil { 23 return nil, err 24 } 25 26 var response models.ExecutionResult 27 err = response.Build(res, link) 28 if err != nil { 29 return nil, err 30 } 31 results[i] = response 32 } 33 34 return results, nil 35 } 36 37 // GetExecutionResultByID gets execution result by the ID. 38 func GetExecutionResultByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) { 39 req, err := r.GetExecutionResultRequest() 40 if err != nil { 41 return nil, NewBadRequestError(err) 42 } 43 44 res, err := backend.GetExecutionResultByID(r.Context(), req.ID) 45 if err != nil { 46 return nil, err 47 } 48 49 if res == nil { 50 err := fmt.Errorf("execution result with ID: %s not found", req.ID.String()) 51 return nil, NewNotFoundError(err.Error(), err) 52 } 53 54 var response models.ExecutionResult 55 err = response.Build(res, link) 56 if err != nil { 57 return nil, err 58 } 59 60 return response, nil 61 }