github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/receipts.go (about) 1 package operation 2 3 import ( 4 "github.com/dgraph-io/badger/v3" 5 6 "github.com/koko1123/flow-go-1/model/flow" 7 ) 8 9 // InsertExecutionReceiptMeta inserts an execution receipt meta by ID. 10 func InsertExecutionReceiptMeta(receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) func(*badger.Txn) error { 11 return insert(makePrefix(codeExecutionReceiptMeta, receiptID), meta) 12 } 13 14 // BatchInsertExecutionReceiptMeta inserts an execution receipt meta by ID. 15 // TODO: rename to BatchUpdate 16 func BatchInsertExecutionReceiptMeta(receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) func(batch *badger.WriteBatch) error { 17 return batchWrite(makePrefix(codeExecutionReceiptMeta, receiptID), meta) 18 } 19 20 // RetrieveExecutionReceipt retrieves a execution receipt meta by ID. 21 func RetrieveExecutionReceiptMeta(receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) func(*badger.Txn) error { 22 return retrieve(makePrefix(codeExecutionReceiptMeta, receiptID), meta) 23 } 24 25 // IndexOwnExecutionReceipt inserts an execution receipt ID keyed by block ID 26 func IndexOwnExecutionReceipt(blockID flow.Identifier, receiptID flow.Identifier) func(*badger.Txn) error { 27 return insert(makePrefix(codeOwnBlockReceipt, blockID), receiptID) 28 } 29 30 // BatchIndexOwnExecutionReceipt inserts an execution receipt ID keyed by block ID into a batch 31 // TODO: rename to BatchUpdate 32 func BatchIndexOwnExecutionReceipt(blockID flow.Identifier, receiptID flow.Identifier) func(batch *badger.WriteBatch) error { 33 return batchWrite(makePrefix(codeOwnBlockReceipt, blockID), receiptID) 34 } 35 36 // LookupOwnExecutionReceipt finds execution receipt ID by block 37 func LookupOwnExecutionReceipt(blockID flow.Identifier, receiptID *flow.Identifier) func(*badger.Txn) error { 38 return retrieve(makePrefix(codeOwnBlockReceipt, blockID), receiptID) 39 } 40 41 // RemoveOwnExecutionReceipt removes own execution receipt index by blockID 42 func RemoveOwnExecutionReceipt(blockID flow.Identifier) func(*badger.Txn) error { 43 return remove(makePrefix(codeOwnBlockReceipt, blockID)) 44 } 45 46 // BatchRemoveOwnExecutionReceipt removes blockID-to-my-receiptID index entries keyed by a blockID in a provided batch. 47 // No errors are expected during normal operation, but it may return generic error 48 // if badger fails to process request 49 func BatchRemoveOwnExecutionReceipt(blockID flow.Identifier) func(batch *badger.WriteBatch) error { 50 return batchRemove(makePrefix(codeOwnBlockReceipt, blockID)) 51 } 52 53 // IndexExecutionReceipts inserts an execution receipt ID keyed by block ID and receipt ID. 54 // one block could have multiple receipts, even if they are from the same executor 55 func IndexExecutionReceipts(blockID, receiptID flow.Identifier) func(*badger.Txn) error { 56 return insert(makePrefix(codeAllBlockReceipts, blockID, receiptID), receiptID) 57 } 58 59 // BatchIndexExecutionReceipts inserts an execution receipt ID keyed by block ID and receipt ID into a batch 60 func BatchIndexExecutionReceipts(blockID, receiptID flow.Identifier) func(batch *badger.WriteBatch) error { 61 return batchWrite(makePrefix(codeAllBlockReceipts, blockID, receiptID), receiptID) 62 } 63 64 // LookupExecutionReceipts finds all execution receipts by block ID 65 func LookupExecutionReceipts(blockID flow.Identifier, receiptIDs *[]flow.Identifier) func(*badger.Txn) error { 66 iterationFunc := receiptIterationFunc(receiptIDs) 67 return traverse(makePrefix(codeAllBlockReceipts, blockID), iterationFunc) 68 } 69 70 // receiptIterationFunc returns an in iteration function which returns all receipt IDs found during traversal 71 func receiptIterationFunc(receiptIDs *[]flow.Identifier) func() (checkFunc, createFunc, handleFunc) { 72 check := func(key []byte) bool { 73 return true 74 } 75 76 var receiptID flow.Identifier 77 create := func() interface{} { 78 return &receiptID 79 } 80 handle := func() error { 81 *receiptIDs = append(*receiptIDs, receiptID) 82 return nil 83 } 84 return func() (checkFunc, createFunc, handleFunc) { 85 return check, create, handle 86 } 87 }