-
Notifications
You must be signed in to change notification settings - Fork 179
/
receipts.go
73 lines (60 loc) · 3.14 KB
/
receipts.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
66
67
68
69
70
71
72
73
package operation
import (
"github.com/dgraph-io/badger/v2"
"github.com/onflow/flow-go/model/flow"
)
// InsertExecutionReceiptMeta inserts an execution receipt meta by ID.
func InsertExecutionReceiptMeta(receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) func(*badger.Txn) error {
return insert(makePrefix(codeExecutionReceiptMeta, receiptID), meta)
}
// BatchInsertExecutionReceiptMeta inserts an execution receipt meta by ID.
func BatchInsertExecutionReceiptMeta(receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) func(batch *badger.WriteBatch) error {
return batchInsert(makePrefix(codeExecutionReceiptMeta, receiptID), meta)
}
// RetrieveExecutionReceipt retrieves a execution receipt meta by ID.
func RetrieveExecutionReceiptMeta(receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) func(*badger.Txn) error {
return retrieve(makePrefix(codeExecutionReceiptMeta, receiptID), meta)
}
// IndexOwnExecutionReceipt inserts an execution receipt ID keyed by block ID
func IndexOwnExecutionReceipt(blockID flow.Identifier, receiptID flow.Identifier) func(*badger.Txn) error {
return insert(makePrefix(codeOwnBlockReceipt, blockID), receiptID)
}
// BatchIndexOwnExecutionReceipt inserts an execution receipt ID keyed by block ID into a batch
func BatchIndexOwnExecutionReceipt(blockID flow.Identifier, receiptID flow.Identifier) func(batch *badger.WriteBatch) error {
return batchInsert(makePrefix(codeOwnBlockReceipt, blockID), receiptID)
}
// LookupOwnExecutionReceipt finds execution receipt ID by block
func LookupOwnExecutionReceipt(blockID flow.Identifier, receiptID *flow.Identifier) func(*badger.Txn) error {
return retrieve(makePrefix(codeOwnBlockReceipt, blockID), receiptID)
}
// IndexExecutionReceipts inserts an execution receipt ID keyed by block ID and receipt ID.
// one block could have multiple receipts, even if they are from the same executor
func IndexExecutionReceipts(blockID, receiptID flow.Identifier) func(*badger.Txn) error {
return insert(makePrefix(codeAllBlockReceipts, blockID, receiptID), receiptID)
}
// BatchIndexExecutionReceipts inserts an execution receipt ID keyed by block ID and receipt ID into a batch
func BatchIndexExecutionReceipts(blockID, receiptID flow.Identifier) func(batch *badger.WriteBatch) error {
return batchInsert(makePrefix(codeAllBlockReceipts, blockID, receiptID), receiptID)
}
// LookupExecutionReceipts finds all execution receipts by block ID
func LookupExecutionReceipts(blockID flow.Identifier, receiptIDs *[]flow.Identifier) func(*badger.Txn) error {
iterationFunc := receiptIterationFunc(receiptIDs)
return traverse(makePrefix(codeAllBlockReceipts, blockID), iterationFunc)
}
// receiptIterationFunc returns an in iteration function which returns all receipt IDs found during traversal
func receiptIterationFunc(receiptIDs *[]flow.Identifier) func() (checkFunc, createFunc, handleFunc) {
check := func(key []byte) bool {
return true
}
var receiptID flow.Identifier
create := func() interface{} {
return &receiptID
}
handle := func() error {
*receiptIDs = append(*receiptIDs, receiptID)
return nil
}
return func() (checkFunc, createFunc, handleFunc) {
return check, create, handle
}
}