-
Notifications
You must be signed in to change notification settings - Fork 175
/
computation_result.go
62 lines (52 loc) · 2.17 KB
/
computation_result.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
package operation
import (
"github.com/dgraph-io/badger/v2"
"github.com/onflow/flow-go/model/flow"
)
// InsertComputationResult addes given instance of ComputationResult into local BadgerDB.
func InsertComputationResultUploadStatus(blockID flow.Identifier,
wasUploadCompleted bool) func(*badger.Txn) error {
return insert(makePrefix(codeComputationResults, blockID), wasUploadCompleted)
}
// UpdateComputationResult updates given existing instance of ComputationResult in local BadgerDB.
func UpdateComputationResultUploadStatus(blockID flow.Identifier,
wasUploadCompleted bool) func(*badger.Txn) error {
return update(makePrefix(codeComputationResults, blockID), wasUploadCompleted)
}
// UpsertComputationResult upserts given existing instance of ComputationResult in local BadgerDB.
func UpsertComputationResultUploadStatus(blockID flow.Identifier,
wasUploadCompleted bool) func(*badger.Txn) error {
return upsert(makePrefix(codeComputationResults, blockID), wasUploadCompleted)
}
// RemoveComputationResult removes an instance of ComputationResult with given ID.
func RemoveComputationResultUploadStatus(
blockID flow.Identifier) func(*badger.Txn) error {
return remove(makePrefix(codeComputationResults, blockID))
}
// GetComputationResult returns stored ComputationResult instance with given ID.
func GetComputationResultUploadStatus(blockID flow.Identifier,
wasUploadCompleted *bool) func(*badger.Txn) error {
return retrieve(makePrefix(codeComputationResults, blockID), wasUploadCompleted)
}
// GetBlockIDsByStatus returns all IDs of stored ComputationResult instances.
func GetBlockIDsByStatus(blockIDs *[]flow.Identifier,
targetUploadStatus bool) func(*badger.Txn) error {
return traverse(makePrefix(codeComputationResults), func() (checkFunc, createFunc, handleFunc) {
var currKey flow.Identifier
check := func(key []byte) bool {
currKey = flow.HashToID(key[1:])
return true
}
var wasUploadCompleted bool
create := func() interface{} {
return &wasUploadCompleted
}
handle := func() error {
if blockIDs != nil && wasUploadCompleted == targetUploadStatus {
*blockIDs = append(*blockIDs, currKey)
}
return nil
}
return check, create, handle
})
}