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

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