github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/collections.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  // NOTE: These insert light collections, which only contain references
    10  // to the constituent transactions. They do not modify transactions contained
    11  // by the collections.
    12  
    13  func InsertCollection(collection *flow.LightCollection) func(*badger.Txn) error {
    14  	return insert(makePrefix(codeCollection, collection.ID()), collection)
    15  }
    16  
    17  func RetrieveCollection(collID flow.Identifier, collection *flow.LightCollection) func(*badger.Txn) error {
    18  	return retrieve(makePrefix(codeCollection, collID), collection)
    19  }
    20  
    21  func RemoveCollection(collID flow.Identifier) func(*badger.Txn) error {
    22  	return remove(makePrefix(codeCollection, collID))
    23  }
    24  
    25  // IndexCollectionPayload indexes the transactions within the collection payload
    26  // of a cluster block.
    27  func IndexCollectionPayload(blockID flow.Identifier, txIDs []flow.Identifier) func(*badger.Txn) error {
    28  	return insert(makePrefix(codeIndexCollection, blockID), txIDs)
    29  }
    30  
    31  // LookupCollection looks up the collection for a given cluster payload.
    32  func LookupCollectionPayload(blockID flow.Identifier, txIDs *[]flow.Identifier) func(*badger.Txn) error {
    33  	return retrieve(makePrefix(codeIndexCollection, blockID), txIDs)
    34  }
    35  
    36  // IndexCollectionByTransaction inserts a collection id keyed by a transaction id
    37  func IndexCollectionByTransaction(txID flow.Identifier, collectionID flow.Identifier) func(*badger.Txn) error {
    38  	return insert(makePrefix(codeIndexCollectionByTransaction, txID), collectionID)
    39  }
    40  
    41  // LookupCollectionID retrieves a collection id by transaction id
    42  func RetrieveCollectionID(txID flow.Identifier, collectionID *flow.Identifier) func(*badger.Txn) error {
    43  	return retrieve(makePrefix(codeIndexCollectionByTransaction, txID), collectionID)
    44  }