-
Notifications
You must be signed in to change notification settings - Fork 178
/
execution_result.go
61 lines (50 loc) · 1.55 KB
/
execution_result.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
package rest
import (
"fmt"
"github.com/onflow/flow-go/access"
"github.com/onflow/flow-go/engine/access/rest/models"
"github.com/onflow/flow-go/engine/access/rest/request"
)
// GetExecutionResultsByBlockIDs gets Execution Result payload by block IDs.
func GetExecutionResultsByBlockIDs(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) {
req, err := r.GetExecutionResultByBlockIDsRequest()
if err != nil {
return nil, NewBadRequestError(err)
}
// for each block ID we retrieve execution result
results := make([]models.ExecutionResult, len(req.BlockIDs))
for i, id := range req.BlockIDs {
res, err := backend.GetExecutionResultForBlockID(r.Context(), id)
if err != nil {
return nil, err
}
var response models.ExecutionResult
err = response.Build(res, link)
if err != nil {
return nil, err
}
results[i] = response
}
return results, nil
}
// GetExecutionResultByID gets execution result by the ID.
func GetExecutionResultByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) {
req, err := r.GetExecutionResultRequest()
if err != nil {
return nil, NewBadRequestError(err)
}
res, err := backend.GetExecutionResultByID(r.Context(), req.ID)
if err != nil {
return nil, err
}
if res == nil {
err := fmt.Errorf("execution result with ID: %s not found", req.ID.String())
return nil, NewNotFoundError(err.Error(), err)
}
var response models.ExecutionResult
err = response.Build(res, link)
if err != nil {
return nil, err
}
return response, nil
}