-
Notifications
You must be signed in to change notification settings - Fork 178
/
index.go
65 lines (59 loc) · 1.92 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
}
err = operation.IndexPayloadReceipts(blockID, index.ReceiptIDs)(tx)
if err != nil {
return fmt.Errorf("could not store receipts index: %w", err)
}
err = operation.IndexPayloadResults(blockID, index.ResultIDs)(tx)
if err != nil {
return fmt.Errorf("could not store results 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)
}
var receiptIDs []flow.Identifier
err = operation.LookupPayloadReceipts(blockID, &receiptIDs)(tx)
if err != nil {
return fmt.Errorf("could not retrieve receipts index: %w", err)
}
var resultsIDs []flow.Identifier
err = operation.LookupPayloadResults(blockID, &resultsIDs)(tx)
if err != nil {
return fmt.Errorf("could not retrieve receipts index: %w", err)
}
*index = flow.Index{
CollectionIDs: collIDs,
SealIDs: sealIDs,
ReceiptIDs: receiptIDs,
ResultIDs: resultsIDs,
}
return nil
}
}