github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/protocol_kv_store.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 // InsertProtocolKVStore inserts a protocol KV store 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 InsertProtocolKVStore(protocolKVStoreID flow.Identifier, kvStore *flow.PSKeyValueStoreData) func(*badger.Txn) error { 14 return insert(makePrefix(codeProtocolKVStore, protocolKVStoreID), kvStore) 15 } 16 17 // RetrieveProtocolKVStore retrieves a protocol KV store 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 RetrieveProtocolKVStore(protocolKVStoreID flow.Identifier, kvStore *flow.PSKeyValueStoreData) func(*badger.Txn) error { 22 return retrieve(makePrefix(codeProtocolKVStore, protocolKVStoreID), kvStore) 23 } 24 25 // IndexProtocolKVStore indexes a protocol KV store 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 29 func IndexProtocolKVStore(blockID flow.Identifier, protocolKVStoreID flow.Identifier) func(*badger.Txn) error { 30 return insert(makePrefix(codeProtocolKVStoreByBlockID, blockID), protocolKVStoreID) 31 } 32 33 // LookupProtocolKVStore finds protocol KV store 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 LookupProtocolKVStore(blockID flow.Identifier, protocolKVStoreID *flow.Identifier) func(*badger.Txn) error { 38 return retrieve(makePrefix(codeProtocolKVStoreByBlockID, blockID), protocolKVStoreID) 39 }