feat!: implement core store API in runtime (#14326)

This commit is contained in:
Aaron Craelius 2022-12-15 16:58:20 -05:00 committed by GitHub
parent 2ad1ef2b09
commit c275ec4d08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 19 deletions

View File

@ -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
}

View File

@ -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}
}

34
runtime/store.go Normal file
View File

@ -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)
}