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