Skip to content

Commit

Permalink
rename msg service receiver k -> m
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Sep 4, 2023
1 parent fff249f commit 628995a
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions x/interchainqueries/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}

func (k msgServer) RegisterInterchainQuery(goCtx context.Context, msg *types.MsgRegisterInterchainQuery) (*types.MsgRegisterInterchainQueryResponse, error) {
func (m msgServer) RegisterInterchainQuery(goCtx context.Context, msg *types.MsgRegisterInterchainQuery) (*types.MsgRegisterInterchainQueryResponse, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelRegisterInterchainQuery)

ctx := sdk.UnwrapSDKContext(goCtx)
ctx.Logger().Debug("RegisterInterchainQuery", "msg", msg)

senderAddr, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
k.Logger(ctx).Debug("RegisterInterchainQuery: failed to parse sender address", "sender_address", msg.Sender)
m.Logger(ctx).Debug("RegisterInterchainQuery: failed to parse sender address", "sender_address", msg.Sender)
return nil, errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Sender)
}

if !k.contractManagerKeeper.HasContractInfo(ctx, senderAddr) {
k.Logger(ctx).Debug("RegisterInterchainQuery: contract not found", "sender_address", msg.Sender)
if !m.contractManagerKeeper.HasContractInfo(ctx, senderAddr) {
m.Logger(ctx).Debug("RegisterInterchainQuery: contract not found", "sender_address", msg.Sender)
return nil, errors.Wrapf(types.ErrNotContract, "%s is not a contract address", msg.Sender)
}

if _, err := k.ibcKeeper.ConnectionKeeper.Connection(goCtx, &ibcconnectiontypes.QueryConnectionRequest{ConnectionId: msg.ConnectionId}); err != nil {
if _, err := m.ibcKeeper.ConnectionKeeper.Connection(goCtx, &ibcconnectiontypes.QueryConnectionRequest{ConnectionId: msg.ConnectionId}); err != nil {
ctx.Logger().Debug("RegisterInterchainQuery: failed to get connection with ID", "message", msg)
return nil, errors.Wrapf(types.ErrInvalidConnectionID, "failed to get connection with ID '%s': %v", msg.ConnectionId, err)
}

lastID := k.GetLastRegisteredQueryKey(ctx)
lastID := m.GetLastRegisteredQueryKey(ctx)
lastID++

params := k.GetParams(ctx)
params := m.GetParams(ctx)

registeredQuery := &types.RegisteredQuery{
Id: lastID,
Expand All @@ -72,14 +72,14 @@ func (k msgServer) RegisterInterchainQuery(goCtx context.Context, msg *types.Msg
RegisteredAtHeight: uint64(ctx.BlockHeader().Height),
}

k.SetLastRegisteredQueryKey(ctx, lastID)
m.SetLastRegisteredQueryKey(ctx, lastID)

if err := k.CollectDeposit(ctx, *registeredQuery); err != nil {
if err := m.CollectDeposit(ctx, *registeredQuery); err != nil {
ctx.Logger().Debug("RegisterInterchainQuery: failed to collect deposit", "message", &msg, "error", err)
return nil, errors.Wrapf(err, "failed to collect deposit")
}

if err := k.SaveQuery(ctx, registeredQuery); err != nil {
if err := m.SaveQuery(ctx, registeredQuery); err != nil {
ctx.Logger().Debug("RegisterInterchainQuery: failed to save query", "message", &msg, "error", err)
return nil, errors.Wrapf(err, "failed to save query: %v", err)
}
Expand All @@ -89,11 +89,11 @@ func (k msgServer) RegisterInterchainQuery(goCtx context.Context, msg *types.Msg
return &types.MsgRegisterInterchainQueryResponse{Id: lastID}, nil
}

func (k msgServer) RemoveInterchainQuery(goCtx context.Context, msg *types.MsgRemoveInterchainQueryRequest) (*types.MsgRemoveInterchainQueryResponse, error) {
func (m msgServer) RemoveInterchainQuery(goCtx context.Context, msg *types.MsgRemoveInterchainQueryRequest) (*types.MsgRemoveInterchainQueryResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
ctx.Logger().Debug("RemoveInterchainQuery", "msg", msg)

query, err := k.GetQueryByID(ctx, msg.GetQueryId())
query, err := m.GetQueryByID(ctx, msg.GetQueryId())
if err != nil {
ctx.Logger().Debug("RemoveInterchainQuery: failed to GetQueryByID",
"error", err, "query_id", msg.QueryId)
Expand All @@ -106,17 +106,17 @@ func (k msgServer) RemoveInterchainQuery(goCtx context.Context, msg *types.MsgRe
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, err.Error())
}

k.RemoveQuery(ctx, query)
k.MustPayOutDeposit(ctx, query.Deposit, msg.GetSigners()[0])
m.RemoveQuery(ctx, query)
m.MustPayOutDeposit(ctx, query.Deposit, msg.GetSigners()[0])
ctx.EventManager().EmitEvents(getEventsQueryRemoved(query))
return &types.MsgRemoveInterchainQueryResponse{}, nil
}

func (k msgServer) UpdateInterchainQuery(goCtx context.Context, msg *types.MsgUpdateInterchainQueryRequest) (*types.MsgUpdateInterchainQueryResponse, error) {
func (m msgServer) UpdateInterchainQuery(goCtx context.Context, msg *types.MsgUpdateInterchainQueryRequest) (*types.MsgUpdateInterchainQueryResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
ctx.Logger().Debug("UpdateInterchainQuery", "msg", msg)

query, err := k.GetQueryByID(ctx, msg.GetQueryId())
query, err := m.GetQueryByID(ctx, msg.GetQueryId())
if err != nil {
ctx.Logger().Debug("UpdateInterchainQuery: failed to GetQueryByID",
"error", err, "query_id", msg.QueryId)
Expand All @@ -129,7 +129,7 @@ func (k msgServer) UpdateInterchainQuery(goCtx context.Context, msg *types.MsgUp
return nil, errors.Wrap(sdkerrors.ErrUnauthorized, "authorization failed")
}

if err := k.validateUpdateInterchainQueryParams(query, msg); err != nil {
if err := m.validateUpdateInterchainQueryParams(query, msg); err != nil {
ctx.Logger().Debug("UpdateInterchainQuery: invalid request",
"error", err, "query_id", msg.QueryId)
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
Expand All @@ -144,7 +144,7 @@ func (k msgServer) UpdateInterchainQuery(goCtx context.Context, msg *types.MsgUp
query.TransactionsFilter = msg.GetNewTransactionsFilter()
}

if err := k.SaveQuery(ctx, query); err != nil {
if err := m.SaveQuery(ctx, query); err != nil {
ctx.Logger().Debug("UpdateInterchainQuery: failed to save query", "message", &msg, "error", err)
return nil, errors.Wrapf(err, "failed to save query by query id: %v", err)
}
Expand All @@ -154,13 +154,13 @@ func (k msgServer) UpdateInterchainQuery(goCtx context.Context, msg *types.MsgUp
return &types.MsgUpdateInterchainQueryResponse{}, nil
}

func (k msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmitQueryResult) (*types.MsgSubmitQueryResultResponse, error) {
func (m msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmitQueryResult) (*types.MsgSubmitQueryResultResponse, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelRegisterInterchainQuery)

ctx := sdk.UnwrapSDKContext(goCtx)
ctx.Logger().Debug("SubmitQueryResult", "query_id", msg.QueryId)

query, err := k.GetQueryByID(ctx, msg.QueryId)
query, err := m.GetQueryByID(ctx, msg.QueryId)
if err != nil {
ctx.Logger().Debug("SubmitQueryResult: failed to GetQueryByID",
"error", err, "query_id", msg.QueryId)
Expand All @@ -178,14 +178,14 @@ func (k msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmit
if !types.InterchainQueryType(query.QueryType).IsKV() {
return nil, errors.Wrapf(types.ErrInvalidType, "invalid query result for query type: %s", query.QueryType)
}
if err := k.checkLastRemoteHeight(ctx, *query, ibcclienttypes.NewHeight(msg.Result.Revision, msg.Result.Height)); err != nil {
if err := m.checkLastRemoteHeight(ctx, *query, ibcclienttypes.NewHeight(msg.Result.Revision, msg.Result.Height)); err != nil {
return nil, errors.Wrap(types.ErrInvalidHeight, err.Error())
}
if len(msg.Result.KvResults) != len(query.Keys) {
return nil, errors.Wrapf(types.ErrInvalidSubmittedResult, "KV keys length from result is not equal to registered query keys length: %v != %v", len(msg.Result.KvResults), len(query.Keys))
}

resp, err := k.ibcKeeper.ConnectionConsensusState(goCtx, &ibcconnectiontypes.QueryConnectionConsensusStateRequest{
resp, err := m.ibcKeeper.ConnectionConsensusState(goCtx, &ibcconnectiontypes.QueryConnectionConsensusStateRequest{
ConnectionId: query.ConnectionId,
RevisionNumber: msg.Result.Revision,
RevisionHeight: msg.Result.Height + 1,
Expand All @@ -209,7 +209,7 @@ func (k msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmit
return nil, errors.Wrapf(sdkerrors.ErrUnpackAny, "failed to cast interface exported.ConsensusState to type *tendermint.ConsensusState")
}

clientState, err := k.GetClientState(ctx, msg.ClientId)
clientState, err := m.GetClientState(ctx, msg.ClientId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -253,15 +253,15 @@ func (k msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmit
}
}

if err = k.saveKVQueryResult(ctx, query, msg.Result); err != nil {
if err = m.saveKVQueryResult(ctx, query, msg.Result); err != nil {
ctx.Logger().Error("SubmitQueryResult: failed to SaveKVQueryResult",
"error", err, "query", query, "message", msg)
return nil, errors.Wrapf(err, "failed to SaveKVQueryResult: %v", err)
}

if msg.Result.GetAllowKvCallbacks() {
// Let the query owner contract process the query result.
if _, err := k.contractManagerKeeper.SudoKVQueryResult(ctx, queryOwner, query.Id); err != nil {
if _, err := m.contractManagerKeeper.SudoKVQueryResult(ctx, queryOwner, query.Id); err != nil {
ctx.Logger().Debug("SubmitQueryResult: failed to SudoKVQueryResult",
"error", err, "query_id", query.GetId())
return nil, errors.Wrapf(err, "contract %s rejected KV query result (query_id: %d)",
Expand All @@ -276,13 +276,13 @@ func (k msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmit
return nil, errors.Wrapf(types.ErrInvalidType, "invalid query result for query type: %s", query.QueryType)
}

if err := k.ProcessBlock(ctx, queryOwner, msg.QueryId, msg.ClientId, msg.Result.Block); err != nil {
if err := m.ProcessBlock(ctx, queryOwner, msg.QueryId, msg.ClientId, msg.Result.Block); err != nil {
ctx.Logger().Debug("SubmitQueryResult: failed to ProcessBlock",
"error", err, "query", query, "message", msg)
return nil, errors.Wrapf(err, "failed to ProcessBlock: %v", err)
}

if err = k.UpdateLastLocalHeight(ctx, query.Id, uint64(ctx.BlockHeight())); err != nil {
if err = m.UpdateLastLocalHeight(ctx, query.Id, uint64(ctx.BlockHeight())); err != nil {
return nil, errors.Wrapf(err,
"failed to update last local height for a result with id %d: %v", query.Id, err)
}
Expand All @@ -293,7 +293,7 @@ func (k msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmit

// validateUpdateInterchainQueryParams checks whether the parameters to be updated corresponds
// with the query type.
func (k msgServer) validateUpdateInterchainQueryParams(
func (m msgServer) validateUpdateInterchainQueryParams(
query *types.RegisteredQuery,
msg *types.MsgUpdateInterchainQueryRequest,
) error {
Expand Down

0 comments on commit 628995a

Please sign in to comment.