Skip to content

Commit

Permalink
feat!: implement core store API in runtime (#14326)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Dec 15, 2022
1 parent 2ad1ef2 commit c275ec4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
19 changes: 0 additions & 19 deletions core/appmodule/service.go

This file was deleted.

20 changes: 20 additions & 0 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -33,6 +35,9 @@ func init() {
ProvideTransientStoreKey,
ProvideMemoryStoreKey,
ProvideDeliverTx,
ProvideKVStoreService,
ProvideMemoryStoreService,
ProvideTransientStoreService,
),
appmodule.Invoke(SetupAppBuilder),
)
Expand Down Expand Up @@ -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 changes: 34 additions & 0 deletions runtime/store.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit c275ec4

Please sign in to comment.