Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"bytes"
"fmt"
"io"
"os"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -28,6 +27,14 @@ func (gr GasEstimateResponse) String() string {
return fmt.Sprintf("gas estimate: %d", gr.GasEstimate)
}

// GenerateOrBroadcastMsgs respects CLI flags and outputs a message
func GenerateOrBroadcastMsgs(cliCtx context.CLIContext, txBldr authtxb.TxBuilder, msgs []sdk.Msg, offline bool) error {
if cliCtx.GenerateOnly {
return PrintUnsignedStdTx(txBldr, cliCtx, msgs, offline)
}
return CompleteAndBroadcastTxCLI(txBldr, cliCtx, msgs)
}

// CompleteAndBroadcastTxCLI implements a utility function that facilitates
// sending a series of messages in a signed transaction given a TxBuilder and a
// QueryContext. It ensures that the account exists, has a proper number and
Expand Down Expand Up @@ -103,7 +110,7 @@ func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), cdc *

// PrintUnsignedStdTx builds an unsigned StdTx and prints it to os.Stdout.
// Don't perform online validation or lookups if offline is true.
func PrintUnsignedStdTx(w io.Writer, txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg, offline bool) (err error) {
func PrintUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg, offline bool) (err error) {
var stdTx auth.StdTx
if offline {
stdTx, err = buildUnsignedStdTxOffline(txBldr, cliCtx, msgs)
Expand All @@ -115,7 +122,7 @@ func PrintUnsignedStdTx(w io.Writer, txBldr authtxb.TxBuilder, cliCtx context.CL
}
json, err := cliCtx.Codec.MarshalJSON(stdTx)
if err == nil {
fmt.Fprintf(w, "%s\n", json)
fmt.Fprintf(cliCtx.Output, "%s\n", json)
}
return
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,7 @@ func TestGaiaCLIQueryTxPagination(t *testing.T) {
barAddr := f.KeyAddress(keyBar)

for i := 1; i <= 30; i++ {
success := executeWrite(t, fmt.Sprintf(
"gaiacli tx send %s --amount=%dfootoken --to=%s --from=foo",
f.Flags(), i, barAddr), app.DefaultKeyPass)
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, int64(i)))
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (f *Fixtures) CLIConfig(key, value string, flags ...string) {

// TxSend is gaiacli tx send
func (f *Fixtures) TxSend(from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("gaiacli tx send %v --amount=%s --to=%s --from=%s", f.Flags(), amount, to, from)
cmd := fmt.Sprintf("gaiacli tx send %s %s %v --from=%s", to, amount, f.Flags(), from)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), app.DefaultKeyPass)
}

Expand Down Expand Up @@ -308,7 +308,7 @@ func (f *Fixtures) TxStakingCreateValidator(from, consPubKey string, amount sdk.

// TxStakingUnbond is gaiacli tx staking unbond
func (f *Fixtures) TxStakingUnbond(from, shares string, validator sdk.ValAddress, flags ...string) bool {
cmd := fmt.Sprintf("gaiacli tx staking unbond %v --from=%s --validator=%s --shares-amount=%v", f.Flags(), from, validator, shares)
cmd := fmt.Sprintf("gaiacli tx staking unbond %s %v --from=%s %v", validator, shares, from, f.Flags())
return executeWrite(f.T, addFlags(cmd, flags), app.DefaultKeyPass)
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/gaia/init/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ following delegation and commission default parameters:

// write the unsigned transaction to the buffer
w := bytes.NewBuffer([]byte{})
if err := utils.PrintUnsignedStdTx(w, txBldr, cliCtx, []sdk.Msg{msg}, true); err != nil {
cliCtx = cliCtx.WithOutput(w)
if err = utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg}, true); err != nil {
return err
}

Expand Down Expand Up @@ -214,7 +215,7 @@ func prepareFlagsForTxCreateValidator(config *cfg.Config, nodeID, ip, chainID st
viper.Set(cli.FlagNodeID, nodeID) // --node-id
viper.Set(cli.FlagIP, ip) // --ip
viper.Set(cli.FlagPubKey, sdk.MustBech32ifyConsPub(valPubKey)) // --pubkey
viper.Set(cli.FlagGenesisFormat, true) // --genesis-format
viper.Set(client.FlagGenerateOnly, true) // --genesis-format
viper.Set(cli.FlagMoniker, config.Moniker) // --moniker
if config.Moniker == "" {
viper.Set(cli.FlagMoniker, viper.GetString(client.FlagName))
Expand Down
16 changes: 4 additions & 12 deletions docs/gaia/gaiacli.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ When you query an account balance with zero tokens, you will get this error: `No
The following command could be used to send coins from one account to another:

```bash
gaiacli tx send \
--amount=10faucetToken \
gaiacli tx send <destination_cosmos> 10faucetToken \
--chain-id=<chain_id> \
--from=<key_name> \
--to=<destination_cosmos>
```

::: warning Note
Expand Down Expand Up @@ -213,23 +211,19 @@ You can simulate a transaction without actually broadcasting it by appending the
`--dry-run` flag to the command line:

```bash
gaiacli tx send \
--amount=10faucetToken \
gaiacli tx send <destination_cosmosaccaddr> 10faucetToken \
--chain-id=<chain_id> \
--from=<key_name> \
--to=<destination_cosmosaccaddr> \
--dry-run
```

Furthermore, you can build a transaction and print its JSON format to STDOUT by
appending `--generate-only` to the list of the command line arguments:

```bash
gaiacli tx send \
--amount=10faucetToken \
gaiacli tx send <destination_cosmosaccaddr> 10faucetToken \
--chain-id=<chain_id> \
--from=<key_name> \
--to=<destination_cosmosaccaddr> \
--generate-only > unsignedSendTx.json
```

Expand Down Expand Up @@ -722,10 +716,8 @@ The first step to create a multisig transaction is to initiate it on behalf
of the multisig address created above:

```bash
gaiacli tx send \
gaiacli tx send cosmos1570v2fq3twt0f0x02vhxpuzc9jc4yl30q2qned 10stake \
--from=<multisig_address> \
--to=cosmos1570v2fq3twt0f0x02vhxpuzc9jc4yl30q2qned \
--amount=10stake \
--generate-only > unsignedTx.json
```

Expand Down
2 changes: 1 addition & 1 deletion docs/gaia/ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NAME: TYPE: ADDRESS: PUBKEY:
This key will only be accessible while the Ledger is plugged in and unlocked. To send some coins with this key, run the following:

```bash
$ gaiacli tx send --from { .Key.Name } --to { .Destination.AccAddr } --chain-id=gaia-7000
$ gaiacli tx send { .Destination.AccAddr } 10stake --from { .Key.Name } --chain-id=gaia-7000
```

You will be asked to review and confirm the transaction on the Ledger. Once you do this you should see the result in the console! Now you can use your Ledger to manage your Atoms and Stake!
2 changes: 0 additions & 2 deletions x/auth/client/cli/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ func GetAccountCmd(storeName string, cdc *codec.Codec) *cobra.Command {
return cliCtx.PrintOutput(acc)
},
}

// Add the flags here and return the command
return client.GetCommands(cmd)[0]
}
9 changes: 4 additions & 5 deletions x/auth/client/cli/multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
// GetSignCommand returns the sign command
func GetMultiSignCommand(codec *amino.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "multisign <file> <name> <<signature>...>",
Use: "multisign [file] [name] [[signature]...]",
Short: "Generate multisig signatures for transactions generated offline",
Long: `Sign transactions created with the --generate-only flag that require multisig signatures.

Read signature(s) from <signature> file(s), generate a multisig signature compliant to the
multisig key <name>, and attach it to the transaction read from <file>. Example:
Read signature(s) from [signature] file(s), generate a multisig signature compliant to the
multisig key [name], and attach it to the transaction read from [file]. Example:

gaiacli multisign transaction.json k1k2k3 k1sig.json k2sig.json k3sig.json

Expand All @@ -43,8 +43,7 @@ recommended to set such parameters manually.
}
cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit")
cmd.Flags().Bool(flagOffline, false, "Offline mode. Do not query a full node")
cmd.Flags().String(flagOutfile, "",
"The document will be written to the given file instead of STDOUT")
cmd.Flags().String(flagOutfile, "", "The document will be written to the given file instead of STDOUT")

// Add the flags here and return the command
return client.PostCommands(cmd)[0]
Expand Down
4 changes: 2 additions & 2 deletions x/auth/client/cli/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const (
// GetSignCommand returns the sign command
func GetSignCommand(codec *amino.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "sign <file>",
Use: "sign [file]",
Short: "Sign transactions generated offline",
Long: `Sign transactions created with the --generate-only flag.
Read a transaction from <file>, sign it, and print its JSON encoding.
Read a transaction from [file], sign it, and print its JSON encoding.

If the flag --signature-only flag is on, it outputs a JSON representation
of the generated signature only.
Expand Down
12 changes: 8 additions & 4 deletions x/bank/client/cli/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"io/ioutil"
"os"
"strings"

"github.com/spf13/cobra"
amino "github.com/tendermint/go-amino"
Expand All @@ -15,11 +16,14 @@ import (
// GetSignCommand returns the sign command
func GetBroadcastCommand(codec *amino.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "broadcast <file>",
Use: "broadcast [file_path]",
Short: "Broadcast transactions generated offline",
Long: `Broadcast transactions created with the --generate-only flag and signed with the sign command.
Read a transaction from <file> and broadcast it to a node. If you supply a dash (-) argument
in place of an input filename, the command reads from standard input.`,
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.

$ gaiacli tx broadcast ./mytxn.json
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prepend with Example or e.g. here.

`),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
cliCtx := context.NewCLIContext().WithCodec(codec)
Expand Down
25 changes: 5 additions & 20 deletions x/bank/client/cli/sendtx.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cli

import (
"os"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
Expand All @@ -13,7 +11,6 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const (
Expand All @@ -24,8 +21,9 @@ const (
// SendTxCmd will create a send tx and sign it with the given key.
func SendTxCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "send",
Use: "send [to_address] [amount]",
Short: "Create and sign a send tx",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
Expand All @@ -36,16 +34,13 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
return err
}

toStr := viper.GetString(flagTo)

to, err := sdk.AccAddressFromBech32(toStr)
to, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

// parse coins trying to be sent
amount := viper.GetString(flagAmount)
coins, err := sdk.ParseCoins(amount)
coins, err := sdk.ParseCoins(args[1])
if err != nil {
return err
}
Expand All @@ -63,18 +58,8 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {

// build and sign the transaction, then broadcast to Tendermint
msg := bank.NewMsgSend(from, to, coins)
if cliCtx.GenerateOnly {
return utils.PrintUnsignedStdTx(os.Stdout, txBldr, cliCtx, []sdk.Msg{msg}, false)
}

return utils.CompleteAndBroadcastTxCLI(txBldr, cliCtx, []sdk.Msg{msg})
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}, false)
},
}

cmd.Flags().String(flagTo, "", "Address to send coins")
cmd.Flags().String(flagAmount, "", "Amount of coins to send")
cmd.MarkFlagRequired(flagTo)
cmd.MarkFlagRequired(flagAmount)

return client.PostCommands(cmd)[0]
}
16 changes: 15 additions & 1 deletion x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -59,6 +60,10 @@ func GetCmdQueryValidatorCommission(queryRoute string, cdc *codec.Codec) *cobra.
Use: "commission [validator]",
Args: cobra.ExactArgs(1),
Short: "Query distribution validator commission",
Long: strings.TrimSpace(`Query validator commission rewards from delegators to that validator:

$ gaiacli query distr commission cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

`),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

Expand All @@ -85,6 +90,10 @@ func GetCmdQueryValidatorSlashes(queryRoute string, cdc *codec.Codec) *cobra.Com
Use: "slashes [validator] [start-height] [end-height]",
Args: cobra.ExactArgs(3),
Short: "Query distribution validator slashes",
Long: strings.TrimSpace(`Query all slashes of a validator for a given block range:

$ gaiacli query distr slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 0 100
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

`),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

Expand Down Expand Up @@ -124,9 +133,14 @@ func GetCmdQueryValidatorSlashes(queryRoute string, cdc *codec.Codec) *cobra.Com
// GetCmdQueryDelegatorRewards implements the query delegator rewards command.
func GetCmdQueryDelegatorRewards(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "rewards [delegator] [validator]",
Use: "rewards [delegator-addr] [<validator-addr>]",
Args: cobra.RangeArgs(1, 2),
Short: "Query all distribution delegator rewards or rewards from a particular validator",
Long: strings.TrimSpace(`Query all rewards earned by a delegator, optionally restrict to rewards from a single validator:

$ gaiacli query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

$ gaiacli query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
`),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

Expand Down
Loading