diff --git a/core/appmodule/service.go b/core/appmodule/service.go deleted file mode 100644 index 39652b1b1c..0000000000 --- a/core/appmodule/service.go +++ /dev/null @@ -1,19 +0,0 @@ -package appmodule - -import ( - "cosmossdk.io/core/intermodule" - "cosmossdk.io/core/store" -) - -// Service bundles all the core services provided by a compliant runtime -// implementation into a single services. -// -// NOTE: If new core services are provided after core v1, they shouldn't be added to this -// interface which would be API breaking, but rather a cosmossdk.io/core/appmodule/v2.Service -// should be created which extends this Service interface with new services. -type Service interface { - store.KVStoreService - store.MemoryStoreService - store.TransientStoreService - intermodule.Client -} diff --git a/runtime/module.go b/runtime/module.go index dac1065337..1f2d37e2fe 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -3,6 +3,8 @@ package runtime import ( "fmt" + "cosmossdk.io/core/store" + abci "github.com/tendermint/tendermint/abci/types" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" @@ -33,6 +35,9 @@ func init() { ProvideTransientStoreKey, ProvideMemoryStoreKey, ProvideDeliverTx, + ProvideKVStoreService, + ProvideMemoryStoreService, + ProvideTransientStoreService, ), appmodule.Invoke(SetupAppBuilder), ) @@ -141,3 +146,18 @@ func ProvideDeliverTx(appBuilder *AppBuilder) func(abci.RequestDeliverTx) abci.R return appBuilder.app.BaseApp.DeliverTx(tx) } } + +func ProvideKVStoreService(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) store.KVStoreService { + storeKey := ProvideKVStoreKey(config, key, app) + return kvStoreService{key: storeKey} +} + +func ProvideMemoryStoreService(key depinject.ModuleKey, app *AppBuilder) store.MemoryStoreService { + storeKey := ProvideMemoryStoreKey(key, app) + return memStoreService{key: storeKey} +} + +func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) store.TransientStoreService { + storeKey := ProvideTransientStoreKey(key, app) + return transientStoreService{key: storeKey} +} diff --git a/runtime/store.go b/runtime/store.go new file mode 100644 index 0000000000..ee4dfd8370 --- /dev/null +++ b/runtime/store.go @@ -0,0 +1,34 @@ +package runtime + +import ( + "context" + + "cosmossdk.io/core/store" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type kvStoreService struct { + key *storetypes.KVStoreKey +} + +func (k kvStoreService) OpenKVStore(ctx context.Context) store.KVStore { + return sdk.UnwrapSDKContext(ctx).KVStore(k.key) +} + +type memStoreService struct { + key *storetypes.MemoryStoreKey +} + +func (m memStoreService) OpenMemoryStore(ctx context.Context) store.KVStore { + return sdk.UnwrapSDKContext(ctx).KVStore(m.key) +} + +type transientStoreService struct { + key *storetypes.TransientStoreKey +} + +func (t transientStoreService) OpenTransientStore(ctx context.Context) store.KVStore { + return sdk.UnwrapSDKContext(ctx).KVStore(t.key) +}