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