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