github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/mempool/stdmap/results.go (about)

     1  package stdmap
     2  
     3  import (
     4  	"github.com/onflow/flow-go/model/flow"
     5  )
     6  
     7  // Results implements the execution results memory pool of the consensus node,
     8  // used to store execution results and to generate block seals.
     9  type Results struct {
    10  	*Backend
    11  }
    12  
    13  // NewResults creates a new memory pool for execution results.
    14  func NewResults(limit uint) (*Results, error) {
    15  
    16  	// create the results memory pool with the lookup maps
    17  	r := &Results{
    18  		Backend: NewBackend(WithLimit(limit)),
    19  	}
    20  
    21  	return r, nil
    22  }
    23  
    24  // Add adds an execution result to the mempool.
    25  func (r *Results) Add(result *flow.ExecutionResult) bool {
    26  	added := r.Backend.Add(result)
    27  	return added
    28  }
    29  
    30  // Remove will remove a result by ID.
    31  func (r *Results) Remove(resultID flow.Identifier) bool {
    32  	removed := r.Backend.Remove(resultID)
    33  	return removed
    34  }
    35  
    36  // ByID will retrieve an approval by ID.
    37  func (r *Results) ByID(resultID flow.Identifier) (*flow.ExecutionResult, bool) {
    38  	entity, exists := r.Backend.ByID(resultID)
    39  	if !exists {
    40  		return nil, false
    41  	}
    42  	result := entity.(*flow.ExecutionResult)
    43  	return result, true
    44  }
    45  
    46  // All will return all execution results in the memory pool.
    47  func (r *Results) All() []*flow.ExecutionResult {
    48  	entities := r.Backend.All()
    49  	results := make([]*flow.ExecutionResult, 0, len(entities))
    50  	for _, entity := range entities {
    51  		results = append(results, entity.(*flow.ExecutionResult))
    52  	}
    53  	return results
    54  }