github.com/onflow/flow-go@v0.33.17/storage/badger/operation/collections.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package operation 4 5 import ( 6 "github.com/dgraph-io/badger/v2" 7 8 "github.com/onflow/flow-go/model/flow" 9 ) 10 11 // NOTE: These insert light collections, which only contain references 12 // to the constituent transactions. They do not modify transactions contained 13 // by the collections. 14 15 func InsertCollection(collection *flow.LightCollection) func(*badger.Txn) error { 16 return insert(makePrefix(codeCollection, collection.ID()), collection) 17 } 18 19 func RetrieveCollection(collID flow.Identifier, collection *flow.LightCollection) func(*badger.Txn) error { 20 return retrieve(makePrefix(codeCollection, collID), collection) 21 } 22 23 func RemoveCollection(collID flow.Identifier) func(*badger.Txn) error { 24 return remove(makePrefix(codeCollection, collID)) 25 } 26 27 // IndexCollectionPayload indexes the transactions within the collection payload 28 // of a cluster block. 29 func IndexCollectionPayload(blockID flow.Identifier, txIDs []flow.Identifier) func(*badger.Txn) error { 30 return insert(makePrefix(codeIndexCollection, blockID), txIDs) 31 } 32 33 // LookupCollection looks up the collection for a given cluster payload. 34 func LookupCollectionPayload(blockID flow.Identifier, txIDs *[]flow.Identifier) func(*badger.Txn) error { 35 return retrieve(makePrefix(codeIndexCollection, blockID), txIDs) 36 } 37 38 // IndexCollectionByTransaction inserts a collection id keyed by a transaction id 39 func IndexCollectionByTransaction(txID flow.Identifier, collectionID flow.Identifier) func(*badger.Txn) error { 40 return insert(makePrefix(codeIndexCollectionByTransaction, txID), collectionID) 41 } 42 43 // LookupCollectionID retrieves a collection id by transaction id 44 func RetrieveCollectionID(txID flow.Identifier, collectionID *flow.Identifier) func(*badger.Txn) error { 45 return retrieve(makePrefix(codeIndexCollectionByTransaction, txID), collectionID) 46 }