-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ClientStoreProvider interface for isolated prefix stores (#…
- Loading branch information
1 parent
8efa5be
commit 3020f38
Showing
17 changed files
with
147 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
"cosmossdk.io/store/prefix" | ||
storetypes "cosmossdk.io/store/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
host "github.com/cosmos/ibc-go/v8/modules/core/24-host" | ||
"github.com/cosmos/ibc-go/v8/modules/core/exported" | ||
) | ||
|
||
var _ exported.ClientStoreProvider = (*storeProvider)(nil) | ||
|
||
type storeProvider struct { | ||
storeKey storetypes.StoreKey | ||
} | ||
|
||
func NewStoreProvider(storeKey storetypes.StoreKey) exported.ClientStoreProvider { | ||
return storeProvider{ | ||
storeKey: storeKey, | ||
} | ||
} | ||
|
||
// ClientStore returns isolated prefix store for each client so they can read/write in separate | ||
// namespace without being able to read/write other client's data | ||
func (s storeProvider) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore { | ||
clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) | ||
return prefix.NewStore(ctx.KVStore(s.storeKey), clientPrefix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 4 additions & 19 deletions
23
modules/light-clients/06-solomachine/internal/keeper/keeper.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,23 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"cosmossdk.io/store/prefix" | ||
storetypes "cosmossdk.io/store/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
host "github.com/cosmos/ibc-go/v8/modules/core/24-host" | ||
) | ||
|
||
// Keeper defines the 06-solomachine Keeper. | ||
// TODO(damian): delete the keeper and put the codec on the LightClientModule? | ||
type Keeper struct { | ||
cdc codec.BinaryCodec | ||
storeKey storetypes.StoreKey | ||
cdc codec.BinaryCodec | ||
} | ||
|
||
// NewKeeper creates and returns a new 06-solomachine keeper. | ||
func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey) Keeper { | ||
func NewKeeper(cdc codec.BinaryCodec) Keeper { | ||
return Keeper{ | ||
cdc: cdc, | ||
storeKey: storeKey, | ||
cdc: cdc, | ||
} | ||
} | ||
|
||
// Codec returns the keeper codec. | ||
func (k Keeper) Codec() codec.BinaryCodec { | ||
return k.cdc | ||
} | ||
|
||
// ClientStore returns a namespaced prefix store for the provided IBC client identifier. | ||
func (k Keeper) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore { | ||
clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) | ||
return prefix.NewStore(ctx.KVStore(k.storeKey), clientPrefix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.