-
Notifications
You must be signed in to change notification settings - Fork 175
/
index.go
45 lines (39 loc) · 1.19 KB
/
index.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
package procedure
import (
"fmt"
"github.com/dgraph-io/badger/v2"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/storage/badger/operation"
)
func InsertIndex(blockID flow.Identifier, index *flow.Index) func(tx *badger.Txn) error {
return func(tx *badger.Txn) error {
err := operation.IndexPayloadGuarantees(blockID, index.CollectionIDs)(tx)
if err != nil {
return fmt.Errorf("could not store guarantee index: %w", err)
}
err = operation.IndexPayloadSeals(blockID, index.SealIDs)(tx)
if err != nil {
return fmt.Errorf("could not store seal index: %w", err)
}
return nil
}
}
func RetrieveIndex(blockID flow.Identifier, index *flow.Index) func(tx *badger.Txn) error {
return func(tx *badger.Txn) error {
var collIDs []flow.Identifier
err := operation.LookupPayloadGuarantees(blockID, &collIDs)(tx)
if err != nil {
return fmt.Errorf("could not retrieve guarantee index: %w", err)
}
var sealIDs []flow.Identifier
err = operation.LookupPayloadSeals(blockID, &sealIDs)(tx)
if err != nil {
return fmt.Errorf("could not retrieve seal index: %w", err)
}
*index = flow.Index{
CollectionIDs: collIDs,
SealIDs: sealIDs,
}
return nil
}
}