func (m msgServer) RespondService(goCtx context.Context, msg *types.MsgRespondService) (*types.MsgRespondServiceResponse, error) {
	provider, err := sdk.AccAddressFromBech32(msg.Provider)
	if err != nil {
		return nil, err
	}
	requestId, err := hex.DecodeString(msg.RequestId)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	request, _, err := m.Keeper.AddResponse(ctx, requestId, provider, msg.Result, msg.Output)
	if err != nil {
		return nil, err
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeRespondService,
			sdk.NewAttribute(types.AttributeKeyRequestContextID, request.RequestContextId),
			sdk.NewAttribute(types.AttributeKeyRequestID, msg.RequestId),
			sdk.NewAttribute(types.AttributeKeyServiceName, request.ServiceName),
			sdk.NewAttribute(types.AttributeKeyProvider, request.Provider),
			sdk.NewAttribute(types.AttributeKeyConsumer, request.Consumer),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Provider),
		),
	})
	return &types.MsgRespondServiceResponse{}, nil
}
RespondService handles MsgRespondService
package keeper
import (
	"context"
	"encoding/hex"
	tmbytes "github.com/tendermint/tendermint/libs/bytes"
	sdk "github.com/cosmos/cosmos-sdk/types"
	sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
	"github.com/irisnet/irismod/modules/service/types"
)
type msgServer struct {
	Keeper
}
var _ types.MsgServer = msgServer{}
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
	return &msgServer{Keeper: keeper}
}
func (m msgServer) DefineService(goCtx context.Context, msg *types.MsgDefineService) (*types.MsgDefineServiceResponse, error) {
	author, err := sdk.AccAddressFromBech32(msg.Author)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	if err := m.Keeper.AddServiceDefinition(
		ctx, msg.Name, msg.Description, msg.Tags, author,
		msg.AuthorDescription, msg.Schemas,
	); err != nil {
		return nil, err
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeCreateDefinition,
			sdk.NewAttribute(types.AttributeKeyServiceName, msg.Name),
			sdk.NewAttribute(types.AttributeKeyAuthor, msg.Author),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Author),
		),
	})
	return &types.MsgDefineServiceResponse{}, nil
}
func (m msgServer) BindService(goCtx context.Context, msg *types.MsgBindService) (*types.MsgBindServiceResponse, error) {
	if _, _, found := m.Keeper.GetModuleServiceByServiceName(msg.ServiceName); found {
		return nil, sdkerrors.Wrapf(types.ErrBindModuleService, "module service %s", msg.ServiceName)
	}
	provider, err := sdk.AccAddressFromBech32(msg.Provider)
	if err != nil {
		return nil, err
	}
	owner, err := sdk.AccAddressFromBech32(msg.Owner)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	if err := m.Keeper.AddServiceBinding(
		ctx, msg.ServiceName, provider, msg.Deposit,
		msg.Pricing, msg.QoS, msg.Options, owner,
	); err != nil {
		return nil, err
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeCreateBinding,
			sdk.NewAttribute(types.AttributeKeyServiceName, msg.ServiceName),
			sdk.NewAttribute(types.AttributeKeyProvider, msg.Provider),
			sdk.NewAttribute(types.AttributeKeyOwner, msg.Owner),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Owner),
		),
	})
	return &types.MsgBindServiceResponse{}, nil
}
func (m msgServer) UpdateServiceBinding(goCtx context.Context, msg *types.MsgUpdateServiceBinding) (*types.MsgUpdateServiceBindingResponse, error) {
	provider, err := sdk.AccAddressFromBech32(msg.Provider)
	if err != nil {
		return nil, err
	}
	owner, err := sdk.AccAddressFromBech32(msg.Owner)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	if err := m.Keeper.UpdateServiceBinding(
		ctx, msg.ServiceName, provider, msg.Deposit,
		msg.Pricing, msg.QoS, msg.Options, owner,
	); err != nil {
		return nil, err
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeUpdateBinding,
			sdk.NewAttribute(types.AttributeKeyServiceName, msg.ServiceName),
			sdk.NewAttribute(types.AttributeKeyProvider, msg.Provider),
			sdk.NewAttribute(types.AttributeKeyOwner, msg.Owner),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Owner),
		),
	})
	return &types.MsgUpdateServiceBindingResponse{}, nil
}
func (m msgServer) SetWithdrawAddress(goCtx context.Context, msg *types.MsgSetWithdrawAddress) (*types.MsgSetWithdrawAddressResponse, error) {
	withdrawAddress, err := sdk.AccAddressFromBech32(msg.WithdrawAddress)
	if err != nil {
		return nil, err
	}
	owner, err := sdk.AccAddressFromBech32(msg.Owner)
	if err != nil {
		return nil, err
	}
	if m.Keeper.blockedAddrs[msg.WithdrawAddress] {
		return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is a module account", msg.WithdrawAddress)
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	m.Keeper.SetWithdrawAddress(ctx, owner, withdrawAddress)
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeSetWithdrawAddress,
			sdk.NewAttribute(types.AttributeKeyOwner, msg.Owner),
			sdk.NewAttribute(types.AttributeKeyWithdrawAddress, msg.WithdrawAddress),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Owner),
		),
	})
	return &types.MsgSetWithdrawAddressResponse{}, nil
}
func (m msgServer) EnableServiceBinding(goCtx context.Context, msg *types.MsgEnableServiceBinding) (*types.MsgEnableServiceBindingResponse, error) {
	provider, err := sdk.AccAddressFromBech32(msg.Provider)
	if err != nil {
		return nil, err
	}
	owner, err := sdk.AccAddressFromBech32(msg.Owner)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	if err := m.Keeper.EnableServiceBinding(ctx, msg.ServiceName, provider, msg.Deposit, owner); err != nil {
		return nil, err
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeEnableBinding,
			sdk.NewAttribute(types.AttributeKeyServiceName, msg.ServiceName),
			sdk.NewAttribute(types.AttributeKeyProvider, msg.Provider),
			sdk.NewAttribute(types.AttributeKeyOwner, msg.Owner),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Owner),
		),
	})
	return &types.MsgEnableServiceBindingResponse{}, nil
}
func (m msgServer) DisableServiceBinding(goCtx context.Context, msg *types.MsgDisableServiceBinding) (*types.MsgDisableServiceBindingResponse, error) {
	provider, err := sdk.AccAddressFromBech32(msg.Provider)
	if err != nil {
		return nil, err
	}
	owner, err := sdk.AccAddressFromBech32(msg.Owner)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	if err := m.Keeper.DisableServiceBinding(ctx, msg.ServiceName, provider, owner); err != nil {
		return nil, err
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeDisableBinding,
			sdk.NewAttribute(types.AttributeKeyServiceName, msg.ServiceName),
			sdk.NewAttribute(types.AttributeKeyProvider, msg.Provider),
			sdk.NewAttribute(types.AttributeKeyOwner, msg.Owner),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Owner),
		),
	})
	return &types.MsgDisableServiceBindingResponse{}, nil
}
func (m msgServer) RefundServiceDeposit(goCtx context.Context, msg *types.MsgRefundServiceDeposit) (*types.MsgRefundServiceDepositResponse, error) {
	provider, err := sdk.AccAddressFromBech32(msg.Provider)
	if err != nil {
		return nil, err
	}
	owner, err := sdk.AccAddressFromBech32(msg.Owner)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	if err := m.Keeper.RefundDeposit(ctx, msg.ServiceName, provider, owner); err != nil {
		return nil, err
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeRefundDeposit,
			sdk.NewAttribute(types.AttributeKeyServiceName, msg.ServiceName),
			sdk.NewAttribute(types.AttributeKeyProvider, msg.Provider),
			sdk.NewAttribute(types.AttributeKeyOwner, msg.Owner),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Owner),
		),
	})
	return &types.MsgRefundServiceDepositResponse{}, nil
}
func (m msgServer) CallService(goCtx context.Context, msg *types.MsgCallService) (*types.MsgCallServiceResponse, error) {
	var reqContextID tmbytes.HexBytes
	var err error
	consumer, err := sdk.AccAddressFromBech32(msg.Consumer)
	if err != nil {
		return nil, err
	}
	ctx := sdk.UnwrapSDKContext(goCtx)
	_, moduleService, found := m.Keeper.GetModuleServiceByServiceName(msg.ServiceName)
	if !found {
		pds := make([]sdk.AccAddress, len(msg.Providers))
		for i, provider := range msg.Providers {
			pd, err := sdk.AccAddressFromBech32(provider)
			if err != nil {
				return nil, err
			}
			pds[i] = pd
		}
		if reqContextID, err = m.Keeper.CreateRequestContext(
			ctx, msg.ServiceName, pds, consumer,
			msg.Input, msg.ServiceFeeCap, msg.Timeout,
			msg.Repeated, msg.RepeatedFrequency,
			msg.RepeatedTotal, types.RUNNING, 0, "",
		); err != nil {
			return nil, err
		}
	} else {
		if reqContextID, err = m.Keeper.CreateRequestContext(
			ctx, msg.ServiceName, []sdk.AccAddress{moduleService.Provider}, consumer,
			msg.Input, msg.ServiceFeeCap, 1, false, 0, 0, types.RUNNING, 0, "",
		); err != nil {
			return nil, err
		}
		if err := m.Keeper.RequestModuleService(ctx, moduleService, reqContextID, consumer, msg.Input); err != nil {
			return nil, err
		}
	}
	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			types.EventTypeCreateContext,
			sdk.NewAttribute(types.AttributeKeyRequestContextID, reqContextID.String()),
			sdk.NewAttribute(types.AttributeKeyServiceName, msg.ServiceName),
			sdk.NewAttribute(types.AttributeKeyConsumer, msg.Consumer),
		),
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Consumer),
		),
	})
	return &types.MsgCallServiceResponse{
		RequestContextId: reqContextID.String(),
	}, nil
}