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

Fix all cli #555

Merged
merged 6 commits into from
Nov 9, 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
6 changes: 3 additions & 3 deletions client/distribution/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func GetDelegationDistInfo(storeName string, cdc *codec.Codec) *cobra.Command {
return err
}
var ddi types.DelegationDistInfo
err = cdc.UnMarshalBinaryLengthPrefixed(res, &ddi)
err = cdc.UnmarshalBinaryLengthPrefixed(res, &ddi)
if err != nil {
return err
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func GetAllDelegationDistInfo(storeName string, cdc *codec.Codec) *cobra.Command
var ddiList []types.DelegationDistInfo
for _, kv := range resKVs {
var ddi types.DelegationDistInfo
err = cdc.UnMarshalBinaryLengthPrefixed(kv.Value, &ddi)
err = cdc.UnmarshalBinaryLengthPrefixed(kv.Value, &ddi)
if err != nil {
return err
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func GetValidatorDistInfo(storeName string, cdc *codec.Codec) *cobra.Command {
return err
}
var vdi types.ValidatorDistInfo
err = cdc.UnMarshalBinaryLengthPrefixed(res, &vdi)
err = cdc.UnmarshalBinaryLengthPrefixed(res, &vdi)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion client/gov/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
flagOption = "option"
flagDepositer = "depositer"
flagStatus = "status"
flagLatestProposalIDs = "latest"
flagNumLimit = "limit"
flagParam = "param"
flagOp = "op"
)
18 changes: 9 additions & 9 deletions client/gov/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
Example: "iriscli gov query-proposal --proposal-id=1",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

params := gov.QueryProposalParams{
ProposalID: proposalID,
Expand Down Expand Up @@ -60,10 +60,10 @@ func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
bechDepositerAddr := viper.GetString(flagDepositer)
bechVoterAddr := viper.GetString(flagVoter)
strProposalStatus := viper.GetString(flagStatus)
latestProposalsIDs := viper.GetInt64(flagLatestProposalIDs)
numLimit := uint64(viper.GetInt64(flagNumLimit))

params := gov.QueryProposalsParams{
NumLatestProposals: latestProposalsIDs,
Limit:numLimit,
}

if len(bechDepositerAddr) != 0 {
Expand Down Expand Up @@ -121,7 +121,7 @@ func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
},
}

cmd.Flags().String(flagLatestProposalIDs, "", "(optional) limit to latest [number] proposals. Defaults to all proposals")
cmd.Flags().String(flagNumLimit, "", "(optional) limit to latest [number] proposals. Defaults to all proposals")
cmd.Flags().String(flagDepositer, "", "(optional) filter by proposals deposited on by depositer")
cmd.Flags().String(flagVoter, "", "(optional) filter by proposals voted on by voted")
cmd.Flags().String(flagStatus, "", "(optional) filter proposals by proposal status")
Expand All @@ -138,7 +138,7 @@ func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command {
Example: "iriscli gov query-vote --proposal-id=1 --voter=<voter address>",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

voterAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagVoter))
if err != nil {
Expand Down Expand Up @@ -178,7 +178,7 @@ func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
Example: "iriscli gov query-votes --proposal-id=1",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

params := gov.QueryVotesParams{
ProposalID: proposalID,
Expand Down Expand Up @@ -211,7 +211,7 @@ func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
Short: "Query details of a deposit",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

depositerAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagDepositer))
if err != nil {
Expand Down Expand Up @@ -250,7 +250,7 @@ func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command {
Short: "Query deposits on a proposal",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

params := gov.QueryDepositsParams{
ProposalID: proposalID,
Expand Down Expand Up @@ -282,7 +282,7 @@ func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command {
Short: "Get the tally of a proposal vote",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

params := gov.QueryTallyParams{
ProposalID: proposalID,
Expand Down
4 changes: 2 additions & 2 deletions client/gov/cli/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func GetCmdDeposit(cdc *codec.Codec) *cobra.Command {
return err
}

proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

//////////////////// iris begin ///////////////////////////
amount, err := cliCtx.ParseCoins(viper.GetString(flagDeposit))
Expand Down Expand Up @@ -169,7 +169,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command {
return err
}

proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))
option := viper.GetString(flagOption)

byteVoteOption, err := gov.VoteOptionFromString(client.NormalizeVoteOption(option))
Expand Down
2 changes: 1 addition & 1 deletion client/gov/lcd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const (
RestDepositer = "depositer"
RestVoter = "voter"
RestProposalStatus = "status"
RestNumLatest = "latest"
RestNumLimit = "limit"
storeName = "gov"
)
20 changes: 10 additions & 10 deletions client/gov/lcd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
return
}

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func queryDepositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
return
}

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func queryVoteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Handle
return
}

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
return
}

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx context.CLIContext)
bechVoterAddr := r.URL.Query().Get(RestVoter)
bechDepositerAddr := r.URL.Query().Get(RestDepositer)
strProposalStatus := r.URL.Query().Get(RestProposalStatus)
strNumLatest := r.URL.Query().Get(RestNumLatest)
strNumLimit := r.URL.Query().Get(RestNumLimit)

params := gov.QueryProposalsParams{}

Expand Down Expand Up @@ -281,12 +281,12 @@ func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx context.CLIContext)
}
params.ProposalStatus = proposalStatus
}
if len(strNumLatest) != 0 {
numLatest, ok := utils.ParseInt64OrReturnBadRequest(w, strNumLatest)
if len(strNumLimit) != 0 {
numLatest, ok := utils.ParseUint64OrReturnBadRequest(w, strNumLimit)
if !ok {
return
}
params.NumLatestProposals = numLatest
params.Limit = numLatest
}

bz, err := cdc.MarshalJSON(params)
Expand Down Expand Up @@ -319,7 +319,7 @@ func queryTallyOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
return
}

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down
4 changes: 2 additions & 2 deletions client/gov/lcd/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func depositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerF
return
}

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc
return
}

proposalID, ok := utils.ParseInt64OrReturnBadRequest(w, strProposalID)
proposalID, ok := utils.ParseUint64OrReturnBadRequest(w, strProposalID)
if !ok {
return
}
Expand Down
4 changes: 2 additions & 2 deletions client/iservice/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func GetCmdQueryScvBind(storeName string, cdc *codec.Codec) *cobra.Command {
}

var svcBinding iservice.SvcBinding
cdc.MustUnmarshalBinary(res, &svcBinding)
cdc.MustUnmarshalBinaryLengthPrefixed(res, &svcBinding)
output, err := codec.MarshalJSONIndent(cdc, svcBinding)
fmt.Println(string(output))
return nil
Expand Down Expand Up @@ -126,7 +126,7 @@ func GetCmdQueryScvBinds(storeName string, cdc *codec.Codec) *cobra.Command {
var bindings []iservice.SvcBinding
for i := 0; i < len(res); i++ {
var binding iservice.SvcBinding
cdc.MustUnmarshalBinary(res[i].Value, &binding)
cdc.MustUnmarshalBinaryLengthPrefixed(res[i].Value, &binding)
bindings = append(bindings, binding)
}

Expand Down
65 changes: 64 additions & 1 deletion client/stake/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,69 @@ func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command {
return cmd
}

// GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegatations from a validator command.
func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "unbonding-delegations-from [operator-addr]",
Short: "Query all unbonding delegatations from a validator",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
valAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
return err
}
cliCtx := context.NewCLIContext().WithCodec(cdc)
params := stake.QueryValidatorParams{
ValidatorAddr: valAddr,
}
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}
res, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/validatorUnbondingDelegations", queryRoute),
bz)
if err != nil {
return err
}
fmt.Println(string(res))
return nil
},
}
return cmd
}
// GetCmdQueryValidatorRedelegations implements the query all redelegatations from a validator command.
func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "redelegations-from [operator-addr]",
Short: "Query all outgoing redelegatations from a validator",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
valAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
return err
}
cliCtx := context.NewCLIContext().WithCodec(cdc)
params := stake.QueryValidatorParams{
ValidatorAddr: valAddr,
}
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}
res, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/validatorRedelegations", queryRoute),
bz)
if err != nil {
return err
}
fmt.Println(string(res))
return nil
},
}
return cmd
}

// GetCmdQueryDelegation the query delegation command.
func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -152,7 +215,7 @@ func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
return fmt.Errorf("no delegation found with delegator %s on validator %s", delAddr, valAddr)
}

// parse out the delegation
// parse out the unbonding delegation
delegation := types.MustUnmarshalDelegation(cdc, key, res)
delegationOutput := stakeClient.ConvertDelegationToDelegationOutput(cliCtx, delegation)
switch viper.Get(cli.OutputFlag) {
Expand Down
2 changes: 1 addition & 1 deletion client/tendermint/tx/querytx.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type Info struct {
func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) {
var tx auth.StdTx

err := cdc.UnMarshalBinaryLengthPrefixed(txBytes, &tx)
err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/upgrade/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func GetCmdQuerySwitch(storeName string, cdc *codec.Codec) *cobra.Command {
Short: "query switch details",
Example: "iriscli upgrade query-switch --proposalID 1 --voter <voter address>",
RunE: func(cmd *cobra.Command, args []string) error {
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))
voterStr := viper.GetString(flagVoter)

voter, err := sdk.AccAddressFromBech32(voterStr)
Expand Down
2 changes: 1 addition & 1 deletion client/upgrade/cli/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetCmdSubmitSwitch(cdc *codec.Codec) *cobra.Command {
Example: "iriscli upgrade submit-switch --chain-id=<chain-id> --from=<key name> --fee=0.004iris --proposalID 1 --title <title>",
RunE: func(cmd *cobra.Command, args []string) error {
title := viper.GetString(flagTitle)
proposalID := viper.GetInt64(flagProposalID)
proposalID := uint64(viper.GetInt64(flagProposalID))

cliCtx := context.NewCLIContext().
WithCodec(cdc).
Expand Down
12 changes: 12 additions & 0 deletions client/utils/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ func ParseInt64OrReturnBadRequest(w http.ResponseWriter, s string) (n int64, ok
return n, true
}

// ParseUint64OrReturnBadRequest converts s to a uint64 value.
func ParseUint64OrReturnBadRequest(w http.ResponseWriter, s string) (n uint64, ok bool) {
var err error
n, err = strconv.ParseUint(s, 10, 64)
if err != nil {
err := fmt.Errorf("'%s' is not a valid uint64", s)
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return n, false
}
return n, true
}

// ParseFloat64OrReturnBadRequest converts s to a float64 value. It returns a
// default value, defaultIfEmpty, if the string is empty.
func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEmpty float64) (n float64, ok bool) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/iriscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func main() {
stakecmd.GetCmdQueryDelegations("stake", cdc),
stakecmd.GetCmdQueryUnbondingDelegation("stake", cdc),
stakecmd.GetCmdQueryUnbondingDelegations("stake", cdc),
stakecmd.GetCmdQueryValidatorUnbondingDelegations("stake", cdc),
stakecmd.GetCmdQueryValidatorRedelegations("stake", cdc),
stakecmd.GetCmdQueryRedelegation("stake", cdc),
stakecmd.GetCmdQueryRedelegations("stake", cdc),
stakecmd.GetCmdQueryPool("stake", cdc),
Expand Down