Remove auth's AccountDecoder type (#4588)
AccountDecoder is now entirely redundant. client package now does no longer depend on x/auth. Context: #4488
This commit is contained in:
parent
1eb7706c28
commit
c530c1cbb7
|
@ -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.
|
|
@ -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
|
||||
|
|
|
@ -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 (
|
||||
|
@ -34,7 +33,6 @@ var (
|
|||
// transaction handling and queries.
|
||||
type CLIContext struct {
|
||||
Codec *codec.Codec
|
||||
AccDecoder authtypes.AccountDecoder
|
||||
Client rpcclient.Client
|
||||
Keybase cryptokeys.Keybase
|
||||
Output io.Writer
|
||||
|
@ -42,7 +40,6 @@ type CLIContext struct {
|
|||
Height int64
|
||||
NodeURI string
|
||||
From string
|
||||
AccountStore string
|
||||
TrustNode bool
|
||||
UseLedger bool
|
||||
BroadcastMode string
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -67,7 +67,6 @@ var (
|
|||
type (
|
||||
Account = types.Account
|
||||
VestingAccount = types.VestingAccount
|
||||
AccountDecoder = types.AccountDecoder
|
||||
BaseAccount = types.BaseAccount
|
||||
BaseVestingAccount = types.BaseVestingAccount
|
||||
ContinuousVestingAccount = types.ContinuousVestingAccount
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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])
|
||||
|
@ -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)
|
||||
|
@ -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])
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -31,7 +31,6 @@ const (
|
|||
type relayCommander struct {
|
||||
cdc *codec.Codec
|
||||
address sdk.AccAddress
|
||||
decoder auth.AccountDecoder
|
||||
mainStore string
|
||||
ibcStore string
|
||||
accStore string
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -50,9 +50,7 @@ func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command {
|
|||
Short: "create new validator initialized with a self-delegation to it",
|
||||
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)
|
||||
|
||||
txBldr, msg, err := BuildCreateValidatorMsg(cliCtx, txBldr)
|
||||
if err != nil {
|
||||
|
@ -88,9 +86,7 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command {
|
|||
Short: "edit an existing validator account",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
valAddr := cliCtx.GetFromAddress()
|
||||
description := types.Description{
|
||||
|
@ -153,9 +149,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10
|
|||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
amount, err := sdk.ParseCoin(args[1])
|
||||
if err != nil {
|
||||
|
@ -191,9 +185,7 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
|||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
delAddr := cliCtx.GetFromAddress()
|
||||
valSrcAddr, err := sdk.ValAddressFromBech32(args[0])
|
||||
|
@ -234,9 +226,7 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s
|
|||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
delAddr := cliCtx.GetFromAddress()
|
||||
valAddr, err := sdk.ValAddressFromBech32(args[0])
|
||||
|
|
Loading…
Reference in New Issue