-
Notifications
You must be signed in to change notification settings - Fork 178
/
results.go
54 lines (45 loc) · 1.36 KB
/
results.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
package stdmap
import (
"github.com/onflow/flow-go/model/flow"
)
// Results implements the execution results memory pool of the consensus node,
// used to store execution results and to generate block seals.
type Results struct {
*Backend
}
// NewResults creates a new memory pool for execution results.
func NewResults(limit uint) (*Results, error) {
// create the results memory pool with the lookup maps
r := &Results{
Backend: NewBackend(WithLimit(limit)),
}
return r, nil
}
// Add adds an execution result to the mempool.
func (r *Results) Add(result *flow.ExecutionResult) bool {
added := r.Backend.Add(result)
return added
}
// Remove will remove a result by ID.
func (r *Results) Remove(resultID flow.Identifier) bool {
removed := r.Backend.Remove(resultID)
return removed
}
// ByID will retrieve an approval by ID.
func (r *Results) ByID(resultID flow.Identifier) (*flow.ExecutionResult, bool) {
entity, exists := r.Backend.ByID(resultID)
if !exists {
return nil, false
}
result := entity.(*flow.ExecutionResult)
return result, true
}
// All will return all execution results in the memory pool.
func (r *Results) All() []*flow.ExecutionResult {
entities := r.Backend.All()
results := make([]*flow.ExecutionResult, 0, len(entities))
for _, entity := range entities {
results = append(results, entity.(*flow.ExecutionResult))
}
return results
}