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

Refactor x/auth/client/utils/ #5555

Merged
merged 2 commits into from
Jan 24, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### API Breaking Changes

* (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move x/auth/client/utils/ types and functions to x/auth/client/.

## [v0.38.0] - 2020-01-23

### State Machine Breaking
Expand Down
4 changes: 2 additions & 2 deletions x/auth/client/cli/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/auth/client"
)

// GetBroadcastCommand returns the tx broadcast command.
Expand All @@ -26,7 +26,7 @@ $ <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])
stdTx, err := client.ReadStdTxFromFile(cliCtx.Codec, args[0])
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions x/auth/client/cli/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/auth/client"
)

// txEncodeRespStr implements a simple Stringer wrapper for a encoded tx.
Expand All @@ -31,7 +31,7 @@ If you supply a dash (-) argument in place of an input filename, the command rea
RunE: func(cmd *cobra.Command, args []string) (err error) {
cliCtx := context.NewCLIContext().WithCodec(cdc)

stdTx, err := utils.ReadStdTxFromFile(cliCtx.Codec, args[0])
stdTx, err := client.ReadStdTxFromFile(cliCtx.Codec, args[0])
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/auth/types"

tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -118,7 +118,7 @@ $ %s query txs --%s 'message.sender=cosmos1...&message.action=withdraw_delegator
limit := viper.GetInt(flags.FlagLimit)

cliCtx := context.NewCLIContext().WithCodec(cdc)
txs, err := utils.QueryTxsByEvents(cliCtx, tmEvents, page, limit)
txs, err := authclient.QueryTxsByEvents(cliCtx, tmEvents, page, limit)
if err != nil {
return err
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func QueryTxCmd(cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

output, err := utils.QueryTx(cliCtx, args[0])
output, err := authclient.QueryTx(cliCtx, args[0])
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

Expand Down Expand Up @@ -60,7 +60,7 @@ recommended to set such parameters manually.

func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) (err error) {
stdTx, err := utils.ReadStdTxFromFile(cdc, args[0])
stdTx, err := client.ReadStdTxFromFile(cdc, args[0])
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

Expand Down Expand Up @@ -94,7 +94,7 @@ func preSignCmd(cmd *cobra.Command, _ []string) {

func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
stdTx, err := utils.ReadStdTxFromFile(cdc, args[0])
stdTx, err := client.ReadStdTxFromFile(cdc, args[0])
if err != nil {
return err
}
Expand Down Expand Up @@ -125,13 +125,13 @@ func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error
return err
}

newTx, err = utils.SignStdTxWithSignerAddress(
newTx, err = client.SignStdTxWithSignerAddress(
txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, offline,
)
generateSignatureOnly = true
} else {
appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly
newTx, err = utils.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, offline)
newTx, err = client.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, offline)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/utils/query.go → x/auth/client/query.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package client

import (
"encoding/hex"
Expand Down
4 changes: 2 additions & 2 deletions x/auth/client/utils/rest.go → x/auth/client/rest.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package client

import (
"log"
Expand Down Expand Up @@ -31,7 +31,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cliCtx context.CLIContext

if br.Simulate || simAndExec {
if gasAdj < 0 {
rest.WriteErrorResponse(w, http.StatusBadRequest, errInvalidGasAdjustment.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, types.ErrorInvalidGasAdjustment.Error())
return
}

Expand Down
6 changes: 3 additions & 3 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/auth/types"
genutilrest "github.com/cosmos/cosmos-sdk/x/genutil/client/rest"
)
Expand Down Expand Up @@ -99,7 +99,7 @@ func QueryTxsRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

searchResult, err := utils.QueryTxsByEvents(cliCtx, events, page, limit)
searchResult, err := client.QueryTxsByEvents(cliCtx, events, page, limit)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand All @@ -121,7 +121,7 @@ func QueryTxRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

output, err := utils.QueryTx(cliCtx, hashHexStr)
output, err := client.QueryTx(cliCtx, hashHexStr)
if err != nil {
if strings.Contains(err.Error(), hashHexStr) {
rest.WriteErrorResponse(w, http.StatusNotFound, err.Error())
Expand Down
6 changes: 3 additions & 3 deletions x/auth/client/utils/tx.go → x/auth/client/tx.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package client

import (
"bufio"
Expand Down Expand Up @@ -182,7 +182,7 @@ func SignStdTx(

// check whether the address is a signer
if !isTxSigner(sdk.AccAddress(addr), stdTx.GetSigners()) {
return signedStdTx, fmt.Errorf("%s: %s", errInvalidSigner, name)
return signedStdTx, fmt.Errorf("%s: %s", authtypes.ErrorInvalidSigner, name)
}

if !offline {
Expand All @@ -204,7 +204,7 @@ func SignStdTxWithSignerAddress(txBldr authtypes.TxBuilder, cliCtx context.CLICo

// check whether the address is a signer
if !isTxSigner(addr, stdTx.GetSigners()) {
return signedStdTx, fmt.Errorf("%s: %s", errInvalidSigner, name)
return signedStdTx, fmt.Errorf("%s: %s", authtypes.ErrorInvalidSigner, name)
}

if !offline {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package client

import (
"encoding/json"
Expand Down
8 changes: 0 additions & 8 deletions x/auth/client/utils/errors.go

This file was deleted.

8 changes: 8 additions & 0 deletions x/auth/types/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package types

import "errors"
alessio marked this conversation as resolved.
Show resolved Hide resolved

var (
ErrorInvalidSigner = errors.New("tx intended signer does not match the given signer")
alessio marked this conversation as resolved.
Show resolved Hide resolved
ErrorInvalidGasAdjustment = errors.New("invalid gas adjustment")
alessio marked this conversation as resolved.
Show resolved Hide resolved
)
6 changes: 3 additions & 3 deletions x/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
)

Expand All @@ -38,7 +38,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithCodec(cdc)

to, err := sdk.AccAddressFromBech32(args[1])
Expand All @@ -54,7 +54,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {

// build and sign the transaction, then broadcast to Tendermint
msg := types.NewMsgSend(cliCtx.GetFromAddress(), to, coins)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}

Expand Down
5 changes: 2 additions & 3 deletions x/bank/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"

authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
)

Expand Down Expand Up @@ -54,6 +53,6 @@ func SendRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}

msg := types.NewMsgSend(fromAddr, toAddr, req.Amount)
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
authclient.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
6 changes: 3 additions & 3 deletions x/crisis/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/crisis/internal/types"
)

Expand All @@ -25,13 +25,13 @@ func GetCmdInvariantBroken(cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {

inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

senderAddr := cliCtx.GetFromAddress()
moduleName, route := args[0], args[1]
msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
Expand Down
22 changes: 11 additions & 11 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/gov"

"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
Expand Down Expand Up @@ -105,7 +105,7 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

delAddr := cliCtx.GetFromAddress()
Expand All @@ -119,7 +119,7 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx
msgs = append(msgs, types.NewMsgWithdrawValidatorCommission(valAddr))
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, msgs)
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, msgs)
},
}
cmd.Flags().Bool(flagCommission, false, "also withdraw validator's commission")
Expand All @@ -143,7 +143,7 @@ $ %s tx distribution withdraw-all-rewards --from mykey
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

delAddr := cliCtx.GetFromAddress()
Expand All @@ -160,7 +160,7 @@ $ %s tx distribution withdraw-all-rewards --from mykey
}

chunkSize := viper.GetInt(flagMaxMessagesPerTx)
return splitAndApply(utils.GenerateOrBroadcastMsgs, cliCtx, txBldr, msgs, chunkSize)
return splitAndApply(authclient.GenerateOrBroadcastMsgs, cliCtx, txBldr, msgs, chunkSize)
},
}

Expand All @@ -186,7 +186,7 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75
RunE: func(cmd *cobra.Command, args []string) error {

inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

delAddr := cliCtx.GetFromAddress()
Expand All @@ -196,7 +196,7 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75
}

msg := types.NewMsgSetWithdrawAddress(delAddr, withdrawAddr)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ Where proposal.json contains:
),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

proposal, err := ParseCommunityPoolSpendProposalJSON(cdc, args[0])
Expand All @@ -255,7 +255,7 @@ Where proposal.json contains:
return err
}

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

Expand All @@ -280,7 +280,7 @@ $ %s tx distribution fund-community-pool 100uatom --from mykey
),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

depositorAddr := cliCtx.GetFromAddress()
Expand All @@ -294,7 +294,7 @@ $ %s tx distribution fund-community-pool 100uatom --from mykey
return err
}

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