func GetCmdRefundServiceDeposit() *cobra.Command {
	cmd := &cobra.Command{
		Use:     "refund-deposit [service-name] [provider-address]",
		Short:   "Refund all deposit from a service binding",
		Long:    "Refund all deposit from a service binding.",
		Example: fmt.Sprintf("$ %s tx service refund-deposit <service-name> <provider-address> --from mykey", version.AppName),
		Args:    cobra.RangeArgs(1, 2),
		RunE: func(cmd *cobra.Command, args []string) error {
			clientCtx, err := client.GetClientTxContext(cmd)
			if err != nil {
				return err
			}
			owner := clientCtx.GetFromAddress().String()
			provider := owner
			if len(args) > 1 {
				if _, err = sdk.AccAddressFromBech32(args[1]); err != nil {
					return err
				}
				provider = args[1]
			}
			msg := types.NewMsgRefundServiceDeposit(args[0], provider, owner)
			if err := msg.ValidateBasic(); err != nil {
				return err
			}
			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
		},
	}
	flags.AddTxFlagsToCmd(cmd)
	return cmd
}
GetCmdRefundServiceDeposit implements refunding deposit command
package cli
import (
	"bytes"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"github.com/spf13/cobra"
	"github.com/cosmos/cosmos-sdk/client"
	"github.com/cosmos/cosmos-sdk/client/flags"
	"github.com/cosmos/cosmos-sdk/client/tx"
	sdk "github.com/cosmos/cosmos-sdk/types"
	"github.com/cosmos/cosmos-sdk/version"
	"github.com/irisnet/irismod/modules/service/types"
)
func NewTxCmd() *cobra.Command {
	serviceTxCmd := &cobra.Command{
		Use:                        types.ModuleName,
		Short:                      "Service transaction subcommands",
		DisableFlagParsing:         true,
		SuggestionsMinimumDistance: 2,
		RunE:                       client.ValidateCmd,
	}
	serviceTxCmd.AddCommand(
		GetCmdDefineService(),
		GetCmdBindService(),
		GetCmdUpdateServiceBinding(),
		GetCmdSetWithdrawAddr(),
		GetCmdDisableServiceBinding(),
		GetCmdEnableServiceBinding(),
		GetCmdRefundServiceDeposit(),
		GetCmdCallService(),
		GetCmdRespondService(),
		GetCmdPauseRequestContext(),
		GetCmdStartRequestContext(),
		GetCmdKillRequestContext(),
		GetCmdUpdateRequestContext(),
		GetCmdWithdrawEarnedFees(),
	)
	return serviceTxCmd
}
func GetCmdDefineService() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "define",
		Short: "Define a new service",
		Long:  "Define a new service based on the given params.",
		Example: fmt.Sprintf(
			"$ %s tx service define "+
				"--name=<service-name> "+
				"--description=<service-description> "+
				"--author-description=<author-description> "+
				"--tags=<tag1,tag2,...> "+
				"--schemas=<schemas content or path/to/schemas.json> "+
				"--from mykey",
			version.AppName,
		),
		RunE: func(cmd *cobra.Command, args []string) error {
			clientCtx, err := client.GetClientTxContext(cmd)
			if err != nil {
				return err
			}
			author := clientCtx.GetFromAddress().String()
			name, err := cmd.Flags().GetString(FlagName)
			if err != nil {
				return err
			}
			description, err := cmd.Flags().GetString(FlagDescription)
			if err != nil {
				return err
			}
			authorDescription, err := cmd.Flags().GetString(FlagAuthorDescription)
			if err != nil {
				return err
			}
			tags, err := cmd.Flags().GetStringSlice(FlagTags)
			if err != nil {
				return err
			}
			schemas, err := cmd.Flags().GetString(FlagSchemas)
			if err != nil {
				return err
			}
			if !json.Valid([]byte(schemas)) {
				schemasContent, err := ioutil.ReadFile(schemas)
				if err != nil {
					return fmt.Errorf("invalid schemas: neither JSON input nor path to .json file were provided")
				}
				if !json.Valid(schemasContent) {
					return fmt.Errorf("invalid schemas: .json file content is invalid JSON")
				}
				schemas = string(schemasContent)
			}
			buf := bytes.NewBuffer([]byte{})
			if err := json.Compact(buf, []byte(schemas)); err != nil {
				return fmt.Errorf("failed to compact the schemas")
			}
			schemas = buf.String()
			fmt.Printf("schemas content: \n%s\n", schemas)
			msg := types.NewMsgDefineService(name, description, tags, author, authorDescription, schemas)
			if err := msg.ValidateBasic(); err != nil {
				return err
			}
			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
		},
	}
	cmd.Flags().AddFlagSet(FsDefineService)
	_ = cmd.MarkFlagRequired(FlagName)
	_ = cmd.MarkFlagRequired(FlagSchemas)
	flags.AddTxFlagsToCmd(cmd)
	return cmd
}
func GetCmdBindService() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "bind",
		Short: "Bind an existing service definition",
		Long:  "Bind an existing service definition.",
		Example: fmt.Sprintf(
			"$ %s tx service bind "+
				"--service-name=<service-name> "+
				"--deposit=1stake "+
				"--pricing=<pricing content or path/to/pricing.json> "+
				"--qos=50 "+
				"--options=<non-functional requirements content or path/to/options.json>"+
				"--from mykey",
			version.AppName,
		),
		RunE: func(cmd *cobra.Command, args []string) error {
			clientCtx, err := client.GetClientTxContext(cmd)
			if err != nil {
				return err
			}
			owner := clientCtx.GetFromAddress().String()
			provider, err := cmd.Flags().GetString(FlagProvider)
			if err != nil {
				return err
			}
			if len(provider) > 0 {
				if _, err = sdk.AccAddressFromBech32(provider); err != nil {
					return err
				}
			} else {
				provider = owner
			}
			serviceName, err := cmd.Flags().GetString(FlagServiceName)
			if err != nil {
				return err
			}
			qos, err := cmd.Flags().GetUint64(FlagQoS)
			if err != nil {
				return err
			}
			options, err := cmd.Flags().GetString(FlagOptions)
			if err != nil {
				return err
			}
			if !json.Valid([]byte(options)) {
				optionsContent, err := ioutil.ReadFile(options)
				if err != nil {
					return fmt.Errorf("invalid options: neither JSON input nor path to .json file were provided")
				}
				if !json.Valid(optionsContent) {
					return fmt.Errorf("invalid options: .json file content is invalid JSON")
				}
				options = string(optionsContent)
			}
			depositStr, err := cmd.Flags().GetString(FlagDeposit)
			if err != nil {
				return err
			}
			deposit, err := sdk.ParseCoinsNormalized(depositStr)
			if err != nil {
				return err
			}
			pricing, err := cmd.Flags().GetString(FlagPricing)
			if err != nil {
				return err
			}
			if !json.Valid([]byte(pricing)) {
				pricingContent, err := ioutil.ReadFile(pricing)
				if err != nil {
					return fmt.Errorf("invalid pricing: neither JSON input nor path to .json file were provided")
				}
				if !json.Valid(pricingContent) {
					return fmt.Errorf("invalid pricing: .json file content is invalid JSON")
				}
				pricing = string(pricingContent)
			}
			buf := bytes.NewBuffer([]byte{})
			if err := json.Compact(buf, []byte(pricing)); err != nil {
				return fmt.Errorf("failed to compact the pricing")
			}
			pricing = buf.String()
			msg := types.NewMsgBindService(serviceName, provider, deposit, pricing, qos, options, owner)
			if err := msg.ValidateBasic(); err != nil {
				return err
			}
			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
		},
	}
	cmd.Flags().AddFlagSet(FsBindService)
	_ = cmd.MarkFlagRequired(FlagServiceName)
	_ = cmd.MarkFlagRequired(FlagDeposit)
	_ = cmd.MarkFlagRequired(FlagPricing)
	_ = cmd.MarkFlagRequired(FlagQoS)
	_ = cmd.MarkFlagRequired(FlagOptions)
	flags.AddTxFlagsToCmd(cmd)
	return cmd
}
func GetCmdUpdateServiceBinding() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "update-binding [service-name] [provider-address]",
		Short: "Update an existing service binding",
		Long:  "Update an existing service binding.",
		Example: fmt.Sprintf(
			"$ %s tx service update-binding <service-name> <provider-address> "+
				"--deposit=1stake "+
				"--pricing=<pricing content or path/to/pricing.json> "+
				"--qos=50 "+
				"--options=<non-functional requirements content or path/to/options.json>"+
				"--from mykey",
			version.AppName,
		),
		Args: cobra.RangeArgs(1, 2),
		RunE: func(cmd *cobra.Command, args []string) error {
			clientCtx, err := client.GetClientTxContext(cmd)
			if err != nil {
				return err
			}
			owner := clientCtx.GetFromAddress().String()
			provider := owner
			if len(args) > 1 {
				if _, err = sdk.AccAddressFromBech32(args[1]); err != nil {
					return err
				}
				provider = args[1]
			}
			var deposit sdk.Coins
			depositStr, err := cmd.Flags().GetString(FlagDeposit)
			if err != nil {
				return err
			}
			if len(depositStr) != 0 {
				deposit, err = sdk.ParseCoinsNormalized(depositStr)
				if err != nil {
					return err
				}
			}
			pricing, err := cmd.Flags().GetString(FlagPricing)
			if err != nil {
				return err
			}
			if len(pricing) != 0 {
				if !json.Valid([]byte(pricing)) {
					pricingContent, err := ioutil.ReadFile(pricing)
					if err != nil {
						return fmt.Errorf("invalid pricing: neither JSON input nor path to .json file were provided")
					}
					if !json.Valid(pricingContent) {
						return fmt.Errorf("invalid pricing: .json file content is invalid JSON")
					}
					pricing = string(pricingContent)
				}
				buf := bytes.NewBuffer([]byte{})
				if err := json.Compact(buf, []byte(pricing)); err != nil {
					return fmt.Errorf("failed to compact the pricing")
				}
				pricing = buf.String()
			}
			qos, err := cmd.Flags().GetUint64(FlagQoS)
			if err != nil {
				return err
			}
			options, err := cmd.Flags().GetString(FlagOptions)
			if err != nil {
				return err
			}
			if len(options) != 0 {
				if !json.Valid([]byte(options)) {
					optionsContent, err := ioutil.ReadFile(options)
					if err != nil {
						return fmt.Errorf("invalid options: neither JSON input nor path to .json file were provided")
					}
					if !json.Valid(optionsContent) {
						return fmt.Errorf("invalid options: .json file content is invalid JSON")
					}
					options = string(optionsContent)
				}
				buf := bytes.NewBuffer([]byte{})
				if err := json.Compact(buf, []byte(options)); err != nil {
					return fmt.Errorf("failed to compact the options")
				}
				options = buf.String()
			}
			msg := types.NewMsgUpdateServiceBinding(args[0], provider, deposit, pricing, qos, options, owner)
			if err := msg.ValidateBasic(); err != nil {
				return err
			}
			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
		},
	}
	cmd.Flags().AddFlagSet(FsUpdateServiceBinding)
	flags.AddTxFlagsToCmd(cmd)
	return cmd
}
func GetCmdSetWithdrawAddr() *cobra.Command {
	cmd := &cobra.Command{
		Use:     "set-withdraw-addr [withdrawal-address]",
		Short:   "Set a withdrawal address for an owner",
		Long:    "Set a withdrawal address for an owner.",
		Example: fmt.Sprintf("$ %s tx service set-withdraw-addr <withdrawal-address> --from mykey", version.AppName),
		Args:    cobra.ExactArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			clientCtx, err := client.GetClientTxContext(cmd)
			if err != nil {
				return err
			}
			owner := clientCtx.GetFromAddress().String()
			if _, err := sdk.AccAddressFromBech32(args[0]); err != nil {
				return err
			}
			msg := types.NewMsgSetWithdrawAddress(owner, args[0])
			if err := msg.ValidateBasic(); err != nil {
				return err
			}
			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
		},
	}
	flags.AddTxFlagsToCmd(cmd)
	return cmd
}
func GetCmdDisableServiceBinding() *cobra.Command {
	cmd := &cobra.Command{
		Use:     "disable [service-name] [provider-address]",
		Short:   "Disable an available service binding",
		Long:    "Disable an available service binding.",
		Example: fmt.Sprintf("$ %s tx service disable <service-name> <provider-address> --from mykey", version.AppName),
		Args:    cobra.RangeArgs(1, 2),
		RunE: func(cmd *cobra.Command, args []string) error {
			clientCtx, err := client.GetClientTxContext(cmd)
			if err != nil {
				return err
			}
			owner := clientCtx.GetFromAddress().String()
			provider := owner
			if len(args) > 1 {
				if _, err = sdk.AccAddressFromBech32(args[1]); err != nil {
					return err
				}
				provider = args[1]
			}
			msg := types.NewMsgDisableServiceBinding(args[0], provider, owner)
			if err := msg.ValidateBasic(); err != nil {
				return err
			}
			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
		},
	}
	flags.AddTxFlagsToCmd(cmd)
	return cmd
}
func GetCmdEnableServiceBinding() *cobra.Command {
	cmd := &cobra.Command{
		Use:     "enable [service-name] [provider-address]",
		Short:   "Enable an unavailable service binding",
		Long:    "Enable an unavailable service binding.",
		Example: fmt.Sprintf("$ %s tx service enable <service-name> <provider-address> --deposit=1stake --from mykey", version.AppName),
		Args:    cobra.RangeArgs(1, 2),
		RunE: func(cmd *cobra.Command, args []string) error {
			clientCtx, err := client.GetClientTxContext(cmd)
			if err != nil {
				return err
			}
			owner := clientCtx.GetFromAddress().String()
			provider := owner
			if len(args) > 1 {
				if _, err = sdk.AccAddressFromBech32(args[1]); err != nil {
					return err
				}
				provider = args[1]
			}
			var deposit sdk.Coins
			depositStr, err := cmd.Flags().GetString(FlagDeposit)
			if err != nil {
				return err
			}
			if len(depositStr) != 0 {
				deposit, err = sdk.ParseCoinsNormalized(depositStr)
				if err != nil {
					return err
				}
			}
			msg := types.NewMsgEnableServiceBinding(args[0], provider, deposit, owner)
			if err := msg.ValidateBasic(); err != nil {
				return err
			}
			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
		},
	}
	cmd.Flags().AddFlagSet(FsEnableServiceBinding)
	flags.AddTxFlagsToCmd(cmd)
	return cmd
}