Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: CLI use --from consistently #1748

Merged
merged 3 commits into from
Jul 19, 2018
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
12 changes: 12 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
BREAKING CHANGES
* [baseapp] Msgs are no longer run on CheckTx, removed `ctx.IsCheckTx()`
* [x/stake] Fixed the period check for the inflation calculation
* \#1606 The following CLI commands have been switched to use `--from`
* `gaiacli stake create-validator --address-validator`
* `gaiacli stake edit-validator --address-validator`
* `gaiacli stake delegate --address-delegator`
* `gaiacli stake unbond begin --address-delegator`
* `gaiacli stake unbond complete --address-delegator`
* `gaiacli stake redelegate begin --address-delegator`
* `gaiacli stake redelegate complete --address-delegator`
* `gaiacli stake unrevoke [validator-address]`
* `gaiacli gov submit-proposal --proposer`
* `gaiacli gov deposit --depositer`
* `gaiacli gov vote --voter`

FEATURES
* [lcd] Can now query governance proposals by ProposalStatus
Expand Down
28 changes: 22 additions & 6 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func TestGaiaCLICreateValidator(t *testing.T) {
// create validator
cvStr := fmt.Sprintf("gaiacli stake create-validator %v", flags)
cvStr += fmt.Sprintf(" --from=%s", "bar")
cvStr += fmt.Sprintf(" --address-validator=%s", barAddr)
cvStr += fmt.Sprintf(" --pubkey=%s", barCeshPubKey)
cvStr += fmt.Sprintf(" --amount=%v", "2steak")
cvStr += fmt.Sprintf(" --moniker=%v", "bar-vally")
Expand All @@ -137,7 +136,6 @@ func TestGaiaCLICreateValidator(t *testing.T) {
unbondStr := fmt.Sprintf("gaiacli stake unbond begin %v", flags)
unbondStr += fmt.Sprintf(" --from=%s", "bar")
unbondStr += fmt.Sprintf(" --address-validator=%s", barAddr)
unbondStr += fmt.Sprintf(" --address-delegator=%s", barAddr)
unbondStr += fmt.Sprintf(" --shares-amount=%v", "1")

success := executeWrite(t, unbondStr, pass)
Expand Down Expand Up @@ -176,7 +174,15 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", fooAddr, flags))
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())

executeWrite(t, fmt.Sprintf("gaiacli gov submit-proposal %v --proposer=%s --deposit=5steak --type=Text --title=Test --description=test --from=foo", flags, fooAddr), pass)
// unbond a single share
spStr := fmt.Sprintf("gaiacli gov submit-proposal %v", flags)
spStr += fmt.Sprintf(" --from=%s", "foo")
spStr += fmt.Sprintf(" --deposit=%s", "5steak")
spStr += fmt.Sprintf(" --type=%s", "Text")
spStr += fmt.Sprintf(" --title=%s", "Test")
spStr += fmt.Sprintf(" --description=%s", "test")

executeWrite(t, spStr, pass)
tests.WaitForNextNBlocksTM(2, port)

fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", fooAddr, flags))
Expand All @@ -186,7 +192,12 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, int64(1), proposal1.GetProposalID())
require.Equal(t, gov.StatusDepositPeriod, proposal1.GetStatus())

executeWrite(t, fmt.Sprintf("gaiacli gov deposit %v --depositer=%s --deposit=10steak --proposalID=1 --from=foo", flags, fooAddr), pass)
depositStr := fmt.Sprintf("gaiacli gov deposit %v", flags)
depositStr += fmt.Sprintf(" --from=%s", "foo")
depositStr += fmt.Sprintf(" --deposit=%s", "10steak")
depositStr += fmt.Sprintf(" --proposalID=%s", "1")

executeWrite(t, depositStr, pass)
tests.WaitForNextNBlocksTM(2, port)

fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", fooAddr, flags))
Expand All @@ -195,10 +206,15 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, int64(1), proposal1.GetProposalID())
require.Equal(t, gov.StatusVotingPeriod, proposal1.GetStatus())

executeWrite(t, fmt.Sprintf("gaiacli gov vote %v --proposalID=1 --voter=%s --option=Yes --from=foo", flags, fooAddr), pass)
voteStr := fmt.Sprintf("gaiacli gov vote %v", flags)
voteStr += fmt.Sprintf(" --from=%s", "foo")
voteStr += fmt.Sprintf(" --proposalID=%s", "1")
voteStr += fmt.Sprintf(" --option=%s", "Yes")

executeWrite(t, voteStr, pass)
tests.WaitForNextNBlocksTM(2, port)

vote := executeGetVote(t, fmt.Sprintf("gaiacli gov query-vote --proposalID=1 --voter=%s --output=json %v", fooAddr, flags))
vote := executeGetVote(t, fmt.Sprintf("gaiacli gov query-vote --proposalID=1 --voter=%s --output=json %v", fooAddr, flags))
require.Equal(t, int64(1), vote.ProposalID)
require.Equal(t, gov.OptionYes, vote.Option)
}
Expand Down
14 changes: 7 additions & 7 deletions docs/sdk/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ On the testnet, we delegate `steak` instead of `atom`. Here's how you can bond t
```bash
gaiacli stake delegate \
--amount=10steak \
--address-delegator=<account_cosmosaccaddr> \
--address-validator=$(gaiad tendermint show_validator) \
--name=<key_name> \
--from=<key_name> \
--chain-id=gaia-6002
```

Expand All @@ -136,15 +135,16 @@ While tokens are bonded, they are pooled with all the other bonded tokens in the
If for any reason the validator misbehaves, or you want to unbond a certain amount of tokens, use this following command. You can unbond a specific amount of`shares`\(eg:`12.1`\) or all of them \(`MAX`\).

```bash
gaiacli stake unbond \
--address-delegator=<account_cosmosaccaddr> \
gaiacli stake unbond begin \
--address-validator=$(gaiad tendermint show_validator) \
--shares=MAX \
--name=<key_name> \
--shares-percent=1 \
--from=<key_name> \
--chain-id=gaia-6002
```

You can check your balance and your stake delegation to see that the unbonding went through successfully.
Later you must use the `gaiacli stake unbond complete` command to finish
unbonding at which point you can can check your balance and your stake
delegation to see that the unbonding went through successfully.

```bash
gaiacli account <account_cosmosaccaddr>
Expand Down
14 changes: 7 additions & 7 deletions docs/sdk/gaiacli.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ On the testnet, we delegate `steak` instead of `atom`. Here's how you can bond t
```bash
gaiacli stake delegate \
--amount=10steak \
--address-delegator=<account_cosmosaccaddr> \
--address-validator=$(gaiad tendermint show_validator) \
--name=<key_name> \
--from=<key_name> \
--chain-id=gaia-6002
```

Expand All @@ -125,15 +124,16 @@ While tokens are bonded, they are pooled with all the other bonded tokens in the
If for any reason the validator misbehaves, or you want to unbond a certain amount of tokens, use this following command. You can unbond a specific amount of`shares`\(eg:`12.1`\) or all of them \(`MAX`\).

```bash
gaiacli stake unbond \
--address-delegator=<account_cosmosaccaddr> \
gaiacli stake unbond begin \
--address-validator=$(gaiad tendermint show_validator) \
--shares=MAX \
--name=<key_name> \
--shares-percent=1 \
--from=<key_name> \
--chain-id=gaia-6002
```

You can check your balance and your stake delegation to see that the unbonding went through successfully.
Later you must use the `gaiacli stake unbond complete` command to finish
unbonding at which point you can can check your balance and your stake
delegation to see that the unbonding went through successfully.

```bash
gaiacli account <account_cosmosaccaddr>
Expand Down
32 changes: 13 additions & 19 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const (
flagDescription = "description"
flagProposalType = "type"
flagDeposit = "deposit"
flagProposer = "proposer"
flagDepositer = "depositer"
flagVoter = "voter"
flagOption = "option"
)
Expand All @@ -32,13 +30,15 @@ func GetCmdSubmitProposal(cdc *wire.Codec) *cobra.Command {
Use: "submit-proposal",
Short: "Submit a proposal along with an initial deposit",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))

title := viper.GetString(flagTitle)
description := viper.GetString(flagDescription)
strProposalType := viper.GetString(flagProposalType)
initialDeposit := viper.GetString(flagDeposit)

// get the from address from the name flag
from, err := sdk.AccAddressFromBech32(viper.GetString(flagProposer))
fromAddr, err := ctx.GetFromAddress()
if err != nil {
return err
}
Expand All @@ -54,18 +54,16 @@ func GetCmdSubmitProposal(cdc *wire.Codec) *cobra.Command {
}

// create the message
msg := gov.NewMsgSubmitProposal(title, description, proposalType, from, amount)
msg := gov.NewMsgSubmitProposal(title, description, proposalType, fromAddr, amount)

err = msg.ValidateBasic()
if err != nil {
return err
}

// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// proposalID must be returned, and it is a part of response
ctx.PrintResponse = true

err = ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, []sdk.Msg{msg}, cdc)
if err != nil {
return err
Expand All @@ -78,7 +76,6 @@ func GetCmdSubmitProposal(cdc *wire.Codec) *cobra.Command {
cmd.Flags().String(flagDescription, "", "description of proposal")
cmd.Flags().String(flagProposalType, "", "proposalType of proposal")
cmd.Flags().String(flagDeposit, "", "deposit of proposal")
cmd.Flags().String(flagProposer, "", "proposer of proposal")

return cmd
}
Expand All @@ -89,8 +86,10 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command {
Use: "deposit",
Short: "deposit tokens for activing proposal",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))

// get the from address from the name flag
depositer, err := sdk.AccAddressFromBech32(viper.GetString(flagDepositer))
depositerAddr, err := ctx.GetFromAddress()
if err != nil {
return err
}
Expand All @@ -103,16 +102,14 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command {
}

// create the message
msg := gov.NewMsgDeposit(depositer, proposalID, amount)
msg := gov.NewMsgDeposit(depositerAddr, proposalID, amount)

err = msg.ValidateBasic()
if err != nil {
return err
}

// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))

err = ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, []sdk.Msg{msg}, cdc)
if err != nil {
return err
Expand All @@ -122,7 +119,6 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command {
}

cmd.Flags().String(flagProposalID, "", "proposalID of proposal depositing on")
cmd.Flags().String(flagDepositer, "", "depositer of deposit")
cmd.Flags().String(flagDeposit, "", "amount of deposit")

return cmd
Expand All @@ -134,9 +130,9 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {
Use: "vote",
Short: "vote for an active proposal, options: Yes/No/NoWithVeto/Abstain",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))

bechVoter := viper.GetString(flagVoter)
voter, err := sdk.AccAddressFromBech32(bechVoter)
voterAddr, err := ctx.GetFromAddress()
if err != nil {
return err
}
Expand All @@ -151,18 +147,17 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {
}

// create the message
msg := gov.NewMsgVote(voter, proposalID, byteVoteOption)
msg := gov.NewMsgVote(voterAddr, proposalID, byteVoteOption)

err = msg.ValidateBasic()
if err != nil {
return err
}

fmt.Printf("Vote[Voter:%s,ProposalID:%d,Option:%s]", bechVoter, msg.ProposalID, msg.Option.String())
fmt.Printf("Vote[Voter:%s,ProposalID:%d,Option:%s]",
voterAddr.String(), msg.ProposalID, msg.Option.String())

// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))

err = ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, []sdk.Msg{msg}, cdc)
if err != nil {
return err
Expand All @@ -172,7 +167,6 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {
}

cmd.Flags().String(flagProposalID, "", "proposalID of proposal voting on")
cmd.Flags().String(flagVoter, "", "bech32 voter address")
cmd.Flags().String(flagOption, "", "vote option {Yes, No, NoWithVeto, Abstain}")

return cmd
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
func GetCmdUnrevoke(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "unrevoke",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(0),
Short: "unrevoke validator previously revoked for downtime",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))

validatorAddr, err := sdk.AccAddressFromBech32(args[0])
validatorAddr, err := ctx.GetFromAddress()
if err != nil {
return err
}
Expand Down
Loading