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

Remove auth's AccountDecoder type #4588

Merged
merged 2 commits into from
Jun 19, 2019
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: 6 additions & 0 deletions .pending/breaking/sdk/4588-Context-does-no
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#4588 Context does not depend on x/auth anymore. client/context is stripped out of the following features:
- GetAccountDecoder()
- CLIContext.WithAccountDecoder()
- CLIContext.WithAccountStore()

x/auth.AccountDecoder is unnecessary and consequently removed.
1 change: 0 additions & 1 deletion client/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ var (
// functions aliases
NewCLIContextWithFrom = context.NewCLIContextWithFrom
NewCLIContext = context.NewCLIContext
GetAccountDecoder = context.GetAccountDecoder
GetFromFields = context.GetFromFields
ErrInvalidAccount = context.ErrInvalidAccount
ErrVerifyCommit = context.ErrVerifyCommit
Expand Down
29 changes: 0 additions & 29 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

var (
Expand All @@ -34,15 +33,13 @@ var (
// transaction handling and queries.
type CLIContext struct {
Codec *codec.Codec
AccDecoder authtypes.AccountDecoder
Client rpcclient.Client
Keybase cryptokeys.Keybase
Output io.Writer
OutputFormat string
Height int64
NodeURI string
From string
AccountStore string
TrustNode bool
UseLedger bool
BroadcastMode string
Expand Down Expand Up @@ -88,7 +85,6 @@ func NewCLIContextWithFrom(from string) CLIContext {
Client: rpc,
Output: os.Stdout,
NodeURI: nodeURI,
AccountStore: authtypes.StoreKey,
From: viper.GetString(flags.FlagFrom),
OutputFormat: viper.GetString(cli.OutputFlag),
Height: viper.GetInt64(flags.FlagHeight),
Expand Down Expand Up @@ -162,37 +158,12 @@ func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext {
return ctx
}

// GetAccountDecoder gets the account decoder for auth.DefaultAccount.
func GetAccountDecoder(cdc *codec.Codec) authtypes.AccountDecoder {
return func(accBytes []byte) (acct authtypes.Account, err error) {
err = cdc.UnmarshalBinaryBare(accBytes, &acct)
if err != nil {
panic(err)
}

return acct, err
}
}

// WithAccountDecoder returns a copy of the context with an updated account
// decoder.
func (ctx CLIContext) WithAccountDecoder(cdc *codec.Codec) CLIContext {
ctx.AccDecoder = GetAccountDecoder(cdc)
return ctx
}

// WithOutput returns a copy of the context with an updated output writer (e.g. stdout).
func (ctx CLIContext) WithOutput(w io.Writer) CLIContext {
ctx.Output = w
return ctx
}

// WithAccountStore returns a copy of the context with an updated AccountStore.
func (ctx CLIContext) WithAccountStore(accountStore string) CLIContext {
ctx.AccountStore = accountStore
return ctx
}

// WithFrom returns a copy of the context with an updated from address or name.
func (ctx CLIContext) WithFrom(from string) CLIContext {
ctx.From = from
Expand Down
2 changes: 1 addition & 1 deletion client/lcd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type RestServer struct {
// NewRestServer creates a new rest server instance
func NewRestServer(cdc *codec.Codec) *RestServer {
r := mux.NewRouter()
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "rest-server")

return &RestServer{
Expand Down
1 change: 0 additions & 1 deletion x/auth/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ var (
type (
Account = types.Account
VestingAccount = types.VestingAccount
AccountDecoder = types.AccountDecoder
BaseAccount = types.BaseAccount
BaseVestingAccount = types.BaseVestingAccount
ContinuousVestingAccount = types.ContinuousVestingAccount
Expand Down
3 changes: 1 addition & 2 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command {
Short: "Query account balance",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().
WithCodec(cdc).WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)
accGetter := types.NewAccountRetriever(cliCtx)

key, err := sdk.AccAddressFromBech32(args[0])
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)

multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold)
multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys))
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)
txBldr := types.NewTxBuilderFromCLI()

if !viper.GetBool(flagOffline) {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error
}

offline := viper.GetBool(flagOffline)
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)
txBldr := types.NewTxBuilderFromCLI()

if viper.GetBool(flagValidateSigs) {
Expand Down
18 changes: 5 additions & 13 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ type AccountWithHeight struct {
}

// query accountREST Handler
func QueryAccountRequestHandlerFn(
storeName string, decoder types.AccountDecoder, cliCtx context.CLIContext,
) http.HandlerFunc {
func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) http.HandlerFunc {

return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Expand All @@ -41,26 +39,20 @@ func QueryAccountRequestHandlerFn(
return
}

res, height, err := cliCtx.QueryStore(types.AddressStoreKey(addr), storeName)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

accGetter := types.NewAccountRetriever(cliCtx)
// the query will return empty account if there is no data
if len(res) == 0 {
if err := accGetter.EnsureExists(addr); err != nil {
rest.PostProcessResponse(w, cliCtx, types.BaseAccount{})
return
}

// decode the value
account, err := decoder(res)
account, err := accGetter.GetAccount(addr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

rest.PostProcessResponse(w, cliCtx, AccountWithHeight{account, height})
rest.PostProcessResponse(w, cliCtx, AccountWithHeight{account, cliCtx.Height})
}
}

Expand Down
3 changes: 1 addition & 2 deletions x/auth/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
// RegisterRoutes registers the auth module REST routes.
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, storeName string) {
r.HandleFunc(
"/auth/accounts/{address}",
QueryAccountRequestHandlerFn(storeName, context.GetAccountDecoder(cliCtx.Codec), cliCtx),
"/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, cliCtx),
).Methods("GET")
}

Expand Down
4 changes: 0 additions & 4 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ type VestingAccount interface {
GetDelegatedVesting() sdk.Coins
}

// AccountDecoder unmarshals account bytes
// TODO: Think about removing
type AccountDecoder func(accountBytes []byte) (Account, error)

//-----------------------------------------------------------------------------
// BaseAccount

Expand Down
4 changes: 1 addition & 3 deletions x/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithFrom(args[0]).
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContextWithFrom(args[0]).WithCodec(cdc)

to, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/crisis/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func GetCmdInvariantBroken(cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

senderAddr := cliCtx.GetFromAddress()
moduleName, route := args[0], args[1]
Expand Down
16 changes: 4 additions & 12 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ $ %s tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqh
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

delAddr := cliCtx.GetFromAddress()
valAddr, err := sdk.ValAddressFromBech32(args[0])
Expand Down Expand Up @@ -142,9 +140,7 @@ $ %s tx distr withdraw-all-rewards --from mykey
RunE: func(cmd *cobra.Command, args []string) error {

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

delAddr := cliCtx.GetFromAddress()
msgs, err := common.WithdrawAllDelegatorRewards(cliCtx, queryRoute, delAddr)
Expand Down Expand Up @@ -178,9 +174,7 @@ $ %s tx set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from m
RunE: func(cmd *cobra.Command, args []string) error {

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

delAddr := cliCtx.GetFromAddress()
withdrawAddr, err := sdk.AccAddressFromBech32(args[0])
Expand Down Expand Up @@ -232,9 +226,7 @@ Where proposal.json contains:
),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

proposal, err := ParseCommunityPoolSpendProposalJSON(cdc, args[0])
if err != nil {
Expand Down
12 changes: 3 additions & 9 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr
),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

proposal, err := parseSubmitProposalFlags()
if err != nil {
Expand Down Expand Up @@ -158,9 +156,7 @@ $ %s tx gov deposit 1 10stake --from mykey
),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

// validate that the proposal id is a uint
proposalID, err := strconv.ParseUint(args[0], 10, 64)
Expand Down Expand Up @@ -207,9 +203,7 @@ $ %s tx gov vote 1 yes --from mykey
),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

// Get voting address
from := cliCtx.GetFromAddress()
Expand Down
4 changes: 1 addition & 3 deletions x/ibc/client/cli/ibctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ func IBCTransferCmd(cdc *codec.Codec) *cobra.Command {
Use: "transfer",
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

from := cliCtx.GetFromAddress()
msg, err := buildMsg(from)
Expand Down
15 changes: 2 additions & 13 deletions x/ibc/client/cli/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const (
type relayCommander struct {
cdc *codec.Codec
address sdk.AccAddress
decoder auth.AccountDecoder
mainStore string
ibcStore string
accStore string
Expand All @@ -43,7 +42,6 @@ type relayCommander struct {
func IBCRelayCmd(cdc *codec.Codec) *cobra.Command {
cmdr := relayCommander{
cdc: cdc,
decoder: context.GetAccountDecoder(cdc),
ibcStore: "ibc",
mainStore: bam.MainStoreKey,
accStore: auth.StoreKey,
Expand Down Expand Up @@ -168,21 +166,12 @@ func (c relayCommander) broadcastTx(node string, tx []byte) error {
}

func (c relayCommander) getSequence(node string) uint64 {
res, err := query(node, auth.AddressStoreKey(c.address), c.accStore)
account, err := auth.NewAccountRetriever(context.NewCLIContext().WithNodeURI(node)).GetAccount(c.address)
if err != nil {
panic(err)
}

if nil != res {
account, err := c.decoder(res)
if err != nil {
panic(err)
}

return account.GetSequence()
}

return 0
return account.GetSequence()
}

func (c relayCommander) refine(bz []byte, ibcSeq, accSeq uint64, passphrase string) []byte {
Expand Down
4 changes: 1 addition & 3 deletions x/params/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ Where proposal.json contains:
),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

proposal, err := paramscutils.ParseParamChangeProposalJSON(cdc, args[0])
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions x/slashing/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ $ <appcli> tx slashing unjail --from mykey
`,
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

valAddr := cliCtx.GetFromAddress()

Expand Down
Loading