@@ -3,7 +3,6 @@ package utils
33import (
44 "bytes"
55 "fmt"
6- "io"
76 "os"
87
98 "github.com/cosmos/cosmos-sdk/client"
@@ -28,6 +27,14 @@ func (gr GasEstimateResponse) String() string {
2827 return fmt .Sprintf ("gas estimate: %d" , gr .GasEstimate )
2928}
3029
30+ // GenerateOrBroadcastMsgs respects CLI flags and outputs a message
31+ func GenerateOrBroadcastMsgs (cliCtx context.CLIContext , txBldr authtxb.TxBuilder , msgs []sdk.Msg , offline bool ) error {
32+ if cliCtx .GenerateOnly {
33+ return PrintUnsignedStdTx (txBldr , cliCtx , msgs , offline )
34+ }
35+ return CompleteAndBroadcastTxCLI (txBldr , cliCtx , msgs )
36+ }
37+
3138// CompleteAndBroadcastTxCLI implements a utility function that facilitates
3239// sending a series of messages in a signed transaction given a TxBuilder and a
3340// QueryContext. It ensures that the account exists, has a proper number and
@@ -103,7 +110,7 @@ func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), cdc *
103110
104111// PrintUnsignedStdTx builds an unsigned StdTx and prints it to os.Stdout.
105112// Don't perform online validation or lookups if offline is true.
106- func PrintUnsignedStdTx (w io. Writer , txBldr authtxb.TxBuilder , cliCtx context.CLIContext , msgs []sdk.Msg , offline bool ) (err error ) {
113+ func PrintUnsignedStdTx (txBldr authtxb.TxBuilder , cliCtx context.CLIContext , msgs []sdk.Msg , offline bool ) (err error ) {
107114 var stdTx auth.StdTx
108115 if offline {
109116 stdTx , err = buildUnsignedStdTxOffline (txBldr , cliCtx , msgs )
@@ -115,7 +122,7 @@ func PrintUnsignedStdTx(w io.Writer, txBldr authtxb.TxBuilder, cliCtx context.CL
115122 }
116123 json , err := cliCtx .Codec .MarshalJSON (stdTx )
117124 if err == nil {
118- fmt .Fprintf (w , "%s\n " , json )
125+ fmt .Fprintf (cliCtx . Output , "%s\n " , json )
119126 }
120127 return
121128}
0 commit comments