Skip to content

Commit

Permalink
chore: remove more UnwrapSDKContext usage
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Dec 18, 2024
1 parent 2b4c3b8 commit 76b6a8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (
var _ types.MsgServer = (*Keeper)(nil)

// Transfer defines an rpc handler method for MsgTransfer.
func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

func (k Keeper) Transfer(ctx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
if !k.GetParams(ctx).SendEnabled {
return nil, types.ErrSendDisabled
}
Expand Down Expand Up @@ -57,12 +55,11 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
}

// UpdateParams defines an rpc handler method for MsgUpdateParams. Updates the ibc-transfer module's parameters.
func (k Keeper) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != msg.Signer {
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer)
}

ctx := sdk.UnwrapSDKContext(goCtx)
k.SetParams(ctx, msg.Params)

return &types.MsgUpdateParamsResponse{}, nil
Expand All @@ -71,7 +68,7 @@ func (k Keeper) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams)
// unwindHops unwinds the hops present in the tokens denomination and returns the message modified to reflect
// the unwound path to take. It assumes that only a single token is present (as this is verified in ValidateBasic)
// in the tokens list and ensures that the token is not native to the chain.
func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgTransfer, error) {
func (k Keeper) unwindHops(ctx context.Context, msg *types.MsgTransfer) (*types.MsgTransfer, error) {
unwindHops, err := k.getUnwindHops(ctx, msg.GetCoins())
if err != nil {
return nil, err
Expand All @@ -92,7 +89,7 @@ func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgT
// getUnwindHops returns the hops to be used during unwinding. If coins consists of more than
// one coin, all coins must have the exact same trace, else an error is returned. getUnwindHops
// also validates that the coins are not native to the chain.
func (k Keeper) getUnwindHops(ctx sdk.Context, coins sdk.Coins) ([]types.Hop, error) {
func (k Keeper) getUnwindHops(ctx context.Context, coins sdk.Coins) ([]types.Hop, error) {
// Sanity: validation for MsgTransfer ensures coins are not empty.
if len(coins) == 0 {
return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "coins cannot be empty")
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
// 5. C -> B : sender chain is sink zone. Denom upon receiving: 'B/denom'
// 6. B -> A : sender chain is sink zone. Denom upon receiving: 'denom'
func (k Keeper) sendTransfer(
ctx sdk.Context,
ctx context.Context,
sourcePort,
sourceChannel string,
coins sdk.Coins,
Expand Down Expand Up @@ -422,7 +422,7 @@ func (k Keeper) unescrowCoin(ctx context.Context, escrowAddress, receiver sdk.Ac
}

// tokenFromCoin constructs an IBC token given an SDK coin.
func (k Keeper) tokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) {
func (k Keeper) tokenFromCoin(ctx context.Context, coin sdk.Coin) (types.Token, error) {
// if the coin does not have an IBC denom, return as is
if !strings.HasPrefix(coin.Denom, "ibc/") {
return types.Token{
Expand Down

0 comments on commit 76b6a8d

Please sign in to comment.