github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/results.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  // InsertExecutionResult inserts an execution result by ID.
    10  func InsertExecutionResult(result *flow.ExecutionResult) func(*badger.Txn) error {
    11  	return insert(makePrefix(codeExecutionResult, result.ID()), result)
    12  }
    13  
    14  // BatchInsertExecutionResult inserts an execution result by ID.
    15  func BatchInsertExecutionResult(result *flow.ExecutionResult) func(batch *badger.WriteBatch) error {
    16  	return batchWrite(makePrefix(codeExecutionResult, result.ID()), result)
    17  }
    18  
    19  // RetrieveExecutionResult retrieves a transaction by fingerprint.
    20  func RetrieveExecutionResult(resultID flow.Identifier, result *flow.ExecutionResult) func(*badger.Txn) error {
    21  	return retrieve(makePrefix(codeExecutionResult, resultID), result)
    22  }
    23  
    24  // IndexExecutionResult inserts an execution result ID keyed by block ID
    25  func IndexExecutionResult(blockID flow.Identifier, resultID flow.Identifier) func(*badger.Txn) error {
    26  	return insert(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
    27  }
    28  
    29  // ReindexExecutionResult updates mapping of an execution result ID keyed by block ID
    30  func ReindexExecutionResult(blockID flow.Identifier, resultID flow.Identifier) func(*badger.Txn) error {
    31  	return update(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
    32  }
    33  
    34  // BatchIndexExecutionResult inserts an execution result ID keyed by block ID into a batch
    35  func BatchIndexExecutionResult(blockID flow.Identifier, resultID flow.Identifier) func(batch *badger.WriteBatch) error {
    36  	return batchWrite(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
    37  }
    38  
    39  // LookupExecutionResult finds execution result ID by block
    40  func LookupExecutionResult(blockID flow.Identifier, resultID *flow.Identifier) func(*badger.Txn) error {
    41  	return retrieve(makePrefix(codeIndexExecutionResultByBlock, blockID), resultID)
    42  }
    43  
    44  // RemoveExecutionResultIndex removes execution result indexed by the given blockID
    45  func RemoveExecutionResultIndex(blockID flow.Identifier) func(*badger.Txn) error {
    46  	return remove(makePrefix(codeIndexExecutionResultByBlock, blockID))
    47  }
    48  
    49  // BatchRemoveExecutionResultIndex removes blockID-to-resultID index entries keyed by a blockID in a provided batch.
    50  // No errors are expected during normal operation, even if no entries are matched.
    51  // If Badger unexpectedly fails to process the request, the error is wrapped in a generic error and returned.
    52  func BatchRemoveExecutionResultIndex(blockID flow.Identifier) func(*badger.WriteBatch) error {
    53  	return batchRemove(makePrefix(codeIndexExecutionResultByBlock, blockID))
    54  }