-
Notifications
You must be signed in to change notification settings - Fork 175
/
results.go
54 lines (43 loc) · 2.55 KB
/
results.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
package operation
import (
"github.com/dgraph-io/badger/v2"
"github.com/onflow/flow-go/model/flow"
)
// InsertExecutionResult inserts an execution result by ID.
func InsertExecutionResult(result *flow.ExecutionResult) func(*badger.Txn) error {
return insert(makePrefix(codeExecutionResult, result.ID()), result)
}
// BatchInsertExecutionResult inserts an execution result by ID.
func BatchInsertExecutionResult(result *flow.ExecutionResult) func(batch *badger.WriteBatch) error {
return batchWrite(makePrefix(codeExecutionResult, result.ID()), result)
}
// RetrieveExecutionResult retrieves a transaction by fingerprint.
func RetrieveExecutionResult(resultID flow.Identifier, result *flow.ExecutionResult) func(*badger.Txn) error {
return retrieve(makePrefix(codeExecutionResult, resultID), result)
}
// IndexExecutionResult inserts an execution result ID keyed by block ID
func IndexExecutionResult(blockID flow.Identifier, resultID flow.Identifier) func(*badger.Txn) error {
return insert(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
}
// ReindexExecutionResult updates mapping of an execution result ID keyed by block ID
func ReindexExecutionResult(blockID flow.Identifier, resultID flow.Identifier) func(*badger.Txn) error {
return update(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
}
// BatchIndexExecutionResult inserts an execution result ID keyed by block ID into a batch
func BatchIndexExecutionResult(blockID flow.Identifier, resultID flow.Identifier) func(batch *badger.WriteBatch) error {
return batchWrite(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
}
// LookupExecutionResult finds execution result ID by block
func LookupExecutionResult(blockID flow.Identifier, resultID *flow.Identifier) func(*badger.Txn) error {
return retrieve(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
}
// RemoveExecutionResultIndex removes execution result indexed by the given blockID
func RemoveExecutionResultIndex(blockID flow.Identifier) func(*badger.Txn) error {
return remove(makePrefix(codeIndexExecutionResultByBlock, blockID))
}
// BatchRemoveExecutionResultIndex removes blockID-to-resultID index entries keyed by a blockID in a provided batch.
// No errors are expected during normal operation, even if no entries are matched.
// If Badger unexpectedly fails to process the request, the error is wrapped in a generic error and returned.
func BatchRemoveExecutionResultIndex(blockID flow.Identifier) func(*badger.WriteBatch) error {
return batchRemove(makePrefix(codeIndexExecutionResultByBlock, blockID))
}