I’m having trouble understanding the flow of this function.
-
Is the ‘internal’ function an anonymous function? Just trying to get the terminology right.
-
The NewHandler function should return an object of type sdk.Handler, right? But the internal function returns a pointer to an sdk.Result and an error object. I don’t understand what’s happening there, how can *sdk.Result, error be returned as a single (and different Type) sdk.Handler?
func NewHandler(keeper Keeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { switch msg := msg.(type) { case MsgSetName: return handleMsgSetName(ctx, keeper, msg) default: return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, fmt.Sprintf("Unrecognized nameservice Msg type: %v", msg.Type())) } } }
sdk.Handler is located here for reference: cosmos-sdk/types/handler.go at v0.38.2 · cosmos/cosmos-sdk · GitHub
type Handler func(ctx Context, msg Msg) (*Result, error)
I know that the code itself is definitely right, I just don’t understand how this is working and also not sure what the right terminology is to be able to look things up.