github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/computation_result.go (about) 1 package operation 2 3 import ( 4 "github.com/dgraph-io/badger/v2" 5 6 "github.com/onflow/flow-go/model/flow" 7 ) 8 9 // InsertComputationResult addes given instance of ComputationResult into local BadgerDB. 10 func InsertComputationResultUploadStatus(blockID flow.Identifier, 11 wasUploadCompleted bool) func(*badger.Txn) error { 12 return insert(makePrefix(codeComputationResults, blockID), wasUploadCompleted) 13 } 14 15 // UpdateComputationResult updates given existing instance of ComputationResult in local BadgerDB. 16 func UpdateComputationResultUploadStatus(blockID flow.Identifier, 17 wasUploadCompleted bool) func(*badger.Txn) error { 18 return update(makePrefix(codeComputationResults, blockID), wasUploadCompleted) 19 } 20 21 // UpsertComputationResult upserts given existing instance of ComputationResult in local BadgerDB. 22 func UpsertComputationResultUploadStatus(blockID flow.Identifier, 23 wasUploadCompleted bool) func(*badger.Txn) error { 24 return upsert(makePrefix(codeComputationResults, blockID), wasUploadCompleted) 25 } 26 27 // RemoveComputationResult removes an instance of ComputationResult with given ID. 28 func RemoveComputationResultUploadStatus( 29 blockID flow.Identifier) func(*badger.Txn) error { 30 return remove(makePrefix(codeComputationResults, blockID)) 31 } 32 33 // GetComputationResult returns stored ComputationResult instance with given ID. 34 func GetComputationResultUploadStatus(blockID flow.Identifier, 35 wasUploadCompleted *bool) func(*badger.Txn) error { 36 return retrieve(makePrefix(codeComputationResults, blockID), wasUploadCompleted) 37 } 38 39 // GetBlockIDsByStatus returns all IDs of stored ComputationResult instances. 40 func GetBlockIDsByStatus(blockIDs *[]flow.Identifier, 41 targetUploadStatus bool) func(*badger.Txn) error { 42 return traverse(makePrefix(codeComputationResults), func() (checkFunc, createFunc, handleFunc) { 43 var currKey flow.Identifier 44 check := func(key []byte) bool { 45 currKey = flow.HashToID(key[1:]) 46 return true 47 } 48 49 var wasUploadCompleted bool 50 create := func() interface{} { 51 return &wasUploadCompleted 52 } 53 54 handle := func() error { 55 if blockIDs != nil && wasUploadCompleted == targetUploadStatus { 56 *blockIDs = append(*blockIDs, currKey) 57 } 58 return nil 59 } 60 return check, create, handle 61 }) 62 }