github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/protocol_state.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 // InsertProtocolState inserts a protocol state by ID. 10 // Error returns: 11 // - storage.ErrAlreadyExists if the key already exists in the database. 12 // - generic error in case of unexpected failure from the database layer or encoding failure. 13 func InsertProtocolState(protocolStateID flow.Identifier, protocolState *flow.ProtocolStateEntry) func(*badger.Txn) error { 14 return insert(makePrefix(codeProtocolState, protocolStateID), protocolState) 15 } 16 17 // RetrieveProtocolState retrieves a protocol state by ID. 18 // Error returns: 19 // - storage.ErrNotFound if the key does not exist in the database 20 // - generic error in case of unexpected failure from the database layer 21 func RetrieveProtocolState(protocolStateID flow.Identifier, protocolState *flow.ProtocolStateEntry) func(*badger.Txn) error { 22 return retrieve(makePrefix(codeProtocolState, protocolStateID), protocolState) 23 } 24 25 // IndexProtocolState indexes a protocol state by block ID. 26 // Error returns: 27 // - storage.ErrAlreadyExists if the key already exists in the database. 28 // - generic error in case of unexpected failure from the database layer or encoding failure. 29 func IndexProtocolState(blockID flow.Identifier, protocolStateID flow.Identifier) func(*badger.Txn) error { 30 return insert(makePrefix(codeProtocolStateByBlockID, blockID), protocolStateID) 31 } 32 33 // LookupProtocolState finds protocol state ID by block ID. 34 // Error returns: 35 // - storage.ErrNotFound if the key does not exist in the database 36 // - generic error in case of unexpected failure from the database layer 37 func LookupProtocolState(blockID flow.Identifier, protocolStateID *flow.Identifier) func(*badger.Txn) error { 38 return retrieve(makePrefix(codeProtocolStateByBlockID, blockID), protocolStateID) 39 }