-
Notifications
You must be signed in to change notification settings - Fork 179
/
seals.go
54 lines (45 loc) · 1.22 KB
/
seals.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"
)
// Seals implements the block seals memory pool of the consensus nodes,
// used to store block seals.
type Seals struct {
*Backend
}
// NewSeals creates a new memory pool for block seals.
func NewSeals(limit uint, opts ...OptionFunc) (*Seals, error) {
s := &Seals{
Backend: NewBackend(append(opts, WithLimit(limit))...),
}
return s, nil
}
// Add adds an block seal to the mempool.
func (s *Seals) Add(seal *flow.Seal) bool {
added := s.Backend.Add(seal)
return added
}
// Rem will remove a seal by ID.
func (s *Seals) Rem(sealID flow.Identifier) bool {
removed := s.Backend.Rem(sealID)
return removed
}
// ByID returns the block seal with the given ID from the mempool.
func (s *Seals) ByID(sealID flow.Identifier) (*flow.Seal, bool) {
entity, exists := s.Backend.ByID(sealID)
if !exists {
return nil, false
}
seal := entity.(*flow.Seal)
return seal, true
}
// All returns all block seals from the pool.
func (s *Seals) All() []*flow.Seal {
entities := s.Backend.All()
seals := make([]*flow.Seal, 0, len(entities))
for _, entity := range entities {
seals = append(seals, entity.(*flow.Seal))
}
return seals
}