From 39318b27406a4e5c76cf18500924a10e013cd057 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Fri, 13 Sep 2024 18:13:32 +0700 Subject: [PATCH] make priv store --- x/asset/keeper/msg_server.go | 10 +++++++++- x/asset/types/privilege.go | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/x/asset/keeper/msg_server.go b/x/asset/keeper/msg_server.go index 1398e94e..d98bfcfb 100644 --- a/x/asset/keeper/msg_server.go +++ b/x/asset/keeper/msg_server.go @@ -9,6 +9,8 @@ import ( errorsmod "cosmossdk.io/errors" bank "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -197,6 +199,12 @@ func (k msgServer) DisablePrivilege(goCtx context.Context, msg *types.MsgDisable return &types.MsgDisablePrivilegeResponse{}, nil } +func (k msgServer) MakePrivilegeStore(ctx sdk.Context, privilegeName string, tokenID string) storetypes.KVStore { + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(tokenID+privilegeName)) + + return store +} + func (k msgServer) ExecutePrivilege(goCtx context.Context, msg *types.MsgExecutePrivilege) (*types.MsgExecutePrivilegeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) userAcc, err := sdk.AccAddressFromBech32(msg.Address) @@ -236,7 +244,7 @@ func (k msgServer) ExecutePrivilege(goCtx context.Context, msg *types.MsgExecute } msgHandler := privImplementation.MsgHandler() - _, err = msgHandler(ctx, sdkMsg, msg.TokenId, userAcc) + _, err = msgHandler(ctx, k.MakePrivilegeStore(ctx, privName, msg.TokenId), sdkMsg, msg.TokenId, userAcc) if err != nil { return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "fail to execute privilege message") } diff --git a/x/asset/types/privilege.go b/x/asset/types/privilege.go index 08387b38..d7fe9e3d 100644 --- a/x/asset/types/privilege.go +++ b/x/asset/types/privilege.go @@ -4,6 +4,7 @@ import ( "context" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/gogo/protobuf/proto" "github.com/spf13/cobra" @@ -22,6 +23,6 @@ type PrivilegeI interface { CLI() *cobra.Command } -type MsgHandler func(context context.Context, msg proto.Message, tokenID string, privAcc sdk.AccAddress) (proto.Message, error) +type MsgHandler func(context context.Context, privStore storetypes.KVStore, msg proto.Message, tokenID string, privAcc sdk.AccAddress) (proto.Message, error) type QueryHandler func(context context.Context, privQuery proto.Message, tokenID string) (proto.Message, error)