From 9671a5c313b0730090c806e446e83377726ac9a3 Mon Sep 17 00:00:00 2001 From: KIMURA Yu <33382781+KimuraYu45z@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:10:09 +0800 Subject: [PATCH] rename --- x/customauth/keeper/keeper_pairing.go | 56 ++++++++++++++++++ x/customauth/keeper/msg_server_pairing.go | 8 +++ .../keeper/{pairing.go => store_pairing.go} | 57 ------------------- ...{pairing_test.go => store_pairing_test.go} | 0 .../keeper/{params.go => store_params.go} | 0 .../{params_test.go => store_params_test.go} | 0 6 files changed, 64 insertions(+), 57 deletions(-) create mode 100644 x/customauth/keeper/keeper_pairing.go rename x/customauth/keeper/{pairing.go => store_pairing.go} (68%) rename x/customauth/keeper/{pairing_test.go => store_pairing_test.go} (100%) rename x/customauth/keeper/{params.go => store_params.go} (100%) rename x/customauth/keeper/{params_test.go => store_params_test.go} (100%) diff --git a/x/customauth/keeper/keeper_pairing.go b/x/customauth/keeper/keeper_pairing.go new file mode 100644 index 0000000..2e8ef92 --- /dev/null +++ b/x/customauth/keeper/keeper_pairing.go @@ -0,0 +1,56 @@ +package keeper + +import ( + "context" + + "gluon/x/customauth/types" + + "gluon/x/customauth/types/pairing" + + errorsmod "cosmossdk.io/errors" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) getPairingPubKey(pairing types.Pairing) (cryptotypes.PubKey, error) { + var pubKey cryptotypes.PubKey + err := k.cdc.UnpackAny(&pairing.PublicKey, &pubKey) + if err != nil { + return nil, err + } + + return pubKey, nil +} + +func (k Keeper) GetPairingPubKey(goCtx context.Context, user sdk.AccAddress, pairingId uint64) (*pairing.PubKeyInternal, error) { + pairingVal, found := k.GetPairing(goCtx, user.String(), pairingId) + if !found { + return nil, errorsmod.Wrapf(types.ErrPairingNotFound, "address: %s, pairing_id: %d", user.String(), pairingId) + } + + params := k.GetParams(goCtx) + + ctx := sdk.UnwrapSDKContext(goCtx) + + if ctx.BlockTime().Compare(pairingVal.CreatedAt.Add(params.ParingDelay)) < 0 { + return nil, errorsmod.Wrapf(types.ErrPairingDelayPeriod, "address: %s, pairing_id: %d", user.String(), pairingId) + } + + pubKey := pairing.PubKeyInternal{ + User: user, + PairingPublicKey: pairingVal.PublicKey, + OperatorPublicKey: params.OperatorPublicKey, + } + + // IMPORTANT: To create cache + // because pairing.PubKey depends on cache + var buffer cryptotypes.PubKey + if err := k.cdc.UnpackAny(&pubKey.PairingPublicKey, &buffer); err != nil { + return nil, err + } + if err := k.cdc.UnpackAny(&pubKey.OperatorPublicKey, &buffer); err != nil { + return nil, err + } + + return &pubKey, nil +} diff --git a/x/customauth/keeper/msg_server_pairing.go b/x/customauth/keeper/msg_server_pairing.go index fdd7546..848ae1c 100644 --- a/x/customauth/keeper/msg_server_pairing.go +++ b/x/customauth/keeper/msg_server_pairing.go @@ -9,11 +9,19 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) func (k msgServer) CreatePairing(goCtx context.Context, msg *types.MsgCreatePairing) (*types.MsgCreatePairingResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + var pubKey cryptotypes.PubKey + err := k.cdc.UnpackAny(&msg.PublicKey, &pubKey) + if err != nil { + return nil, err + } + var pairing = types.Pairing{ Address: msg.User, PublicKey: msg.PublicKey, diff --git a/x/customauth/keeper/pairing.go b/x/customauth/keeper/store_pairing.go similarity index 68% rename from x/customauth/keeper/pairing.go rename to x/customauth/keeper/store_pairing.go index 139810f..f053136 100644 --- a/x/customauth/keeper/pairing.go +++ b/x/customauth/keeper/store_pairing.go @@ -9,12 +9,6 @@ import ( "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/runtime" - - "gluon/x/customauth/types/pairing" - - errorsmod "cosmossdk.io/errors" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) // GetPairingCount get the total number of pairing @@ -48,14 +42,6 @@ func (k Keeper) AppendPairing( ctx context.Context, pairing types.Pairing, ) (uint64, error) { - // - var pubKey cryptotypes.PubKey - err := k.cdc.UnpackAny(&pairing.PublicKey, &pubKey) - if err != nil { - return 0, err - } - // - // Create the pairing count := k.GetPairingCount(ctx) @@ -124,46 +110,3 @@ func GetPairingIDBytes(address string, id uint64) []byte { bz = binary.BigEndian.AppendUint64(bz, id) return bz } - -func (k Keeper) getPairingPubKey(pairing types.Pairing) (cryptotypes.PubKey, error) { - var pubKey cryptotypes.PubKey - err := k.cdc.UnpackAny(&pairing.PublicKey, &pubKey) - if err != nil { - return nil, err - } - - return pubKey, nil -} - -func (k Keeper) GetPairingPubKey(goCtx context.Context, user sdk.AccAddress, pairingId uint64) (*pairing.PubKeyInternal, error) { - pairingVal, found := k.GetPairing(goCtx, user.String(), pairingId) - if !found { - return nil, errorsmod.Wrapf(types.ErrPairingNotFound, "address: %s, pairing_id: %d", user.String(), pairingId) - } - - params := k.GetParams(goCtx) - - ctx := sdk.UnwrapSDKContext(goCtx) - - if ctx.BlockTime().Compare(pairingVal.CreatedAt.Add(params.ParingDelay)) < 0 { - return nil, errorsmod.Wrapf(types.ErrPairingDelayPeriod, "address: %s, pairing_id: %d", user.String(), pairingId) - } - - pubKey := pairing.PubKeyInternal{ - User: user, - PairingPublicKey: pairingVal.PublicKey, - OperatorPublicKey: params.OperatorPublicKey, - } - - // IMPORTANT: To create cache - // because pairing.PubKey depends on cache - var buffer cryptotypes.PubKey - if err := k.cdc.UnpackAny(&pubKey.PairingPublicKey, &buffer); err != nil { - return nil, err - } - if err := k.cdc.UnpackAny(&pubKey.OperatorPublicKey, &buffer); err != nil { - return nil, err - } - - return &pubKey, nil -} diff --git a/x/customauth/keeper/pairing_test.go b/x/customauth/keeper/store_pairing_test.go similarity index 100% rename from x/customauth/keeper/pairing_test.go rename to x/customauth/keeper/store_pairing_test.go diff --git a/x/customauth/keeper/params.go b/x/customauth/keeper/store_params.go similarity index 100% rename from x/customauth/keeper/params.go rename to x/customauth/keeper/store_params.go diff --git a/x/customauth/keeper/params_test.go b/x/customauth/keeper/store_params_test.go similarity index 100% rename from x/customauth/keeper/params_test.go rename to x/customauth/keeper/store_params_test.go