github.com/lino-network/lino@v0.6.11/x/price/client/cli/tx.go (about)

     1  package cli
     2  
     3  import (
     4  	"github.com/cosmos/cosmos-sdk/codec"
     5  	sdk "github.com/cosmos/cosmos-sdk/types"
     6  	"github.com/spf13/cobra"
     7  
     8  	"github.com/lino-network/lino/client"
     9  	linotypes "github.com/lino-network/lino/types"
    10  	"github.com/lino-network/lino/x/price/types"
    11  )
    12  
    13  func GetTxCmd(cdc *codec.Codec) *cobra.Command {
    14  	cmd := &cobra.Command{
    15  		Use:                        types.ModuleName,
    16  		Short:                      "Price tx subcommands",
    17  		DisableFlagParsing:         true,
    18  		SuggestionsMinimumDistance: 2,
    19  		RunE:                       client.ValidateCmd,
    20  	}
    21  
    22  	cmd.AddCommand(client.PostCommands(
    23  		GetCmdFeedPrice(cdc),
    24  	)...)
    25  
    26  	return cmd
    27  }
    28  
    29  // GetCmdFeedPrice - feed price
    30  func GetCmdFeedPrice(cdc *codec.Codec) *cobra.Command {
    31  	cmd := &cobra.Command{
    32  		Use:   "feed <username> <amount>",
    33  		Short: "feed <username> <amount>",
    34  		Args:  cobra.ExactArgs(2),
    35  		RunE: func(cmd *cobra.Command, args []string) error {
    36  			ctx := client.NewCoreContextFromViper().WithTxEncoder(linotypes.TxEncoder(cdc))
    37  			user := linotypes.AccountKey(args[0])
    38  			amount := args[1]
    39  			amt, ok := sdk.NewIntFromString(amount)
    40  			if !ok {
    41  				panic("Invalid price")
    42  			}
    43  
    44  			msg := types.FeedPriceMsg{
    45  				Username: user,
    46  				Price:    linotypes.NewMiniDollarFromInt(amt),
    47  			}
    48  			return ctx.DoTxPrintResponse(msg)
    49  		},
    50  	}
    51  	return cmd
    52  }