github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/auth/client/cli/broadcast.go (about)

     1  package cli
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags"
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    11  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/utils"
    12  )
    13  
    14  // GetBroadcastCommand returns the tx broadcast command.
    15  func GetBroadcastCommand(cdc *codec.Codec) *cobra.Command {
    16  	cmd := &cobra.Command{
    17  		Use:   "broadcast [file_path]",
    18  		Short: "Broadcast transactions generated offline",
    19  		Long: strings.TrimSpace(`Broadcast transactions created with the --generate-only
    20  flag and signed with the sign command. Read a transaction from [file_path] and
    21  broadcast it to a node. If you supply a dash (-) argument in place of an input
    22  filename, the command reads from standard input.
    23  
    24  $ <appcli> tx broadcast ./mytxn.json
    25  `),
    26  		Args: cobra.ExactArgs(1),
    27  		RunE: func(cmd *cobra.Command, args []string) (err error) {
    28  			cliCtx := context.NewCLIContext().WithCodec(cdc)
    29  			stdTx, err := utils.ReadStdTxFromFile(cliCtx.Codec, args[0])
    30  			if err != nil {
    31  				return
    32  			}
    33  
    34  			txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(stdTx)
    35  			if err != nil {
    36  				return
    37  			}
    38  
    39  			res, err := cliCtx.BroadcastTx(txBytes)
    40  			cliCtx.PrintOutput(res)
    41  
    42  			return err
    43  		},
    44  	}
    45  
    46  	return flags.PostCommands(cmd)[0]
    47  }