From 756d38b328cb71827e08d6b029ba0b4b14d66696 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 23 Jan 2019 21:32:02 -0800 Subject: [PATCH] Revert CLIContext to immutability --- client/context/context.go | 63 +++++++++++++++++---------------- client/context/query.go | 2 +- client/context/tx.go | 32 ++++++++--------- client/lcd/root.go | 4 +-- client/rpc/block.go | 8 ++--- client/rpc/root.go | 4 +-- client/rpc/status.go | 6 ++-- client/rpc/validators.go | 6 ++-- client/tx/broadcast.go | 2 +- client/tx/query.go | 6 ++-- client/tx/root.go | 2 +- client/tx/search.go | 4 +-- client/utils/rest.go | 4 +-- cmd/gaia/init/gentx.go | 2 +- x/auth/client/cli/account.go | 2 +- x/auth/client/cli/multisign.go | 2 +- x/auth/client/cli/sign.go | 2 +- x/auth/client/rest/query.go | 6 ++-- x/auth/client/rest/sign.go | 2 +- x/bank/client/rest/broadcast.go | 4 +-- x/bank/client/rest/sendtx.go | 4 +-- x/gov/client/rest/rest.go | 26 +++++++------- x/gov/client/utils/query.go | 12 +++---- x/ibc/client/cli/relay.go | 4 +-- x/ibc/client/rest/transfer.go | 4 +-- x/slashing/client/rest/query.go | 6 ++-- x/slashing/client/rest/rest.go | 2 +- x/slashing/client/rest/tx.go | 4 +-- x/staking/client/cli/tx.go | 16 ++++----- x/staking/client/cli/utils.go | 2 +- x/staking/client/rest/query.go | 30 ++++++++-------- x/staking/client/rest/rest.go | 2 +- x/staking/client/rest/tx.go | 8 ++--- x/staking/client/rest/utils.go | 10 +++--- 34 files changed, 148 insertions(+), 145 deletions(-) diff --git a/client/context/context.go b/client/context/context.go index 2ed397ca0f8d..70418a14b11c 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -50,7 +50,7 @@ type CLIContext struct { // NewCLIContext returns a new initialized CLIContext with parameters from the // command line using Viper. -func NewCLIContext(cdc *codec.Codec) *CLIContext { +func NewCLIContext(cdc *codec.Codec) CLIContext { var rpc rpcclient.Client nodeURI := viper.GetString(client.FlagNode) @@ -65,7 +65,7 @@ func NewCLIContext(cdc *codec.Codec) *CLIContext { verifier = createVerifier() } - return &CLIContext{ + return CLIContext{ Client: rpc, Codec: cdc, Output: os.Stdout, @@ -88,73 +88,76 @@ func NewCLIContext(cdc *codec.Codec) *CLIContext { } } -func NewCLIContextTx(cdc *codec.Codec) *CLIContext { - ctx := NewCLIContext(cdc).SetAccountDecoder() - ctx.PrepareTxBldrOffline() +func NewCLIContextTx(cdc *codec.Codec) CLIContext { + ctx := NewCLIContext(cdc).WithAccountDecoder().WithTxBldrOffline() return ctx } -// PrepareTxBldrOffline sets the transaction builder for the context w/o +// WithTxBldrAddressOffline sets the transaction builder for the context w/o // setting the sequence or account numbers -func (ctx *CLIContext) PrepareTxBldrOffline() { +func (ctx CLIContext) WithTxBldrOffline() CLIContext { ctx.TxBldr = authtxb.NewTxBuilderFromCLI().WithTxEncoder(GetTxEncoder(ctx.Codec)) + return ctx } -// PrepareTxBldrWithAddress looks up the acc and seq numbs for an addr, also +// WithTxBldrAddress looks up the acc and seq numbs for an addr, also // ensuring it exists -func (ctx *CLIContext) PrepareTxBldrWithAddress(addr sdk.AccAddress) error { +func (ctx CLIContext) WithTxBldrAddress(addr sdk.AccAddress) (CLIContext, error) { if err := ctx.EnsureAccountExists(addr); err != nil { - return err + return ctx, err } if ctx.TxBldr.GetAccountNumber() == 0 || ctx.TxBldr.GetSequence() == 0 { accNum, seq, err := ctx.FetchAccAndSeqNums(addr) if err != nil { - return err + return ctx, err } ctx.TxBldr = ctx.TxBldr.WithAccountNumber(accNum).WithSequence(seq) } - return nil + return ctx, nil } -// SetAccountDecoder returns a copy of the context with an updated account +// WithMemo adds a memo to the TxBldr on the CLIContext +func (ctx CLIContext) WithMemo(s string) CLIContext { + ctx.TxBldr = ctx.TxBldr.WithMemo(s) + return ctx +} + +// WithAccountDecoder returns a copy of the context with an updated account // decoder. -func (ctx *CLIContext) SetAccountDecoder() *CLIContext { +func (ctx CLIContext) WithAccountDecoder() CLIContext { ctx.AccDecoder = ctx.GetAccountDecoder() return ctx } // GetAccountDecoder gets the account decoder for auth.DefaultAccount. -func (ctx *CLIContext) GetAccountDecoder() auth.AccountDecoder { +func (ctx CLIContext) GetAccountDecoder() auth.AccountDecoder { return func(accBytes []byte) (acct auth.Account, err error) { - err = ctx.Codec.UnmarshalBinaryBare(accBytes, &acct) - if err != nil { - // TODO: remove this, and return the error, - // but first figure out where this is used - panic(err) + if err = ctx.Codec.UnmarshalBinaryBare(accBytes, &acct); err != nil { + return } - return acct, err + return } } // GetFromAddress returns the from address from the context's name. -func (ctx *CLIContext) FromAddr() sdk.AccAddress { +func (ctx CLIContext) FromAddr() sdk.AccAddress { return ctx.fromAddress } // GetFromAddress returns the from address from the context's name // in validator format -func (ctx *CLIContext) FromValAddr() sdk.ValAddress { +func (ctx CLIContext) FromValAddr() sdk.ValAddress { return sdk.ValAddress(ctx.fromAddress.Bytes()) } // GetFromName returns the key name for the current context. -func (ctx *CLIContext) FromName() string { +func (ctx CLIContext) FromName() string { return ctx.fromName } -// SetNode returns a copy of the context with an updated node URI. -func (ctx *CLIContext) SetNode(nodeURI string) *CLIContext { +// WithNode returns a copy of the context with an updated node URI. +func (ctx CLIContext) WithNode(nodeURI string) CLIContext { ctx.NodeURI = nodeURI ctx.Client = rpcclient.NewHTTP(nodeURI, "/websocket") return ctx @@ -162,7 +165,7 @@ func (ctx *CLIContext) SetNode(nodeURI string) *CLIContext { // GetNode returns an RPC client. If the context's client is not defined, an // error is returned. -func (ctx *CLIContext) GetNode() (rpcclient.Client, error) { +func (ctx CLIContext) GetNode() (rpcclient.Client, error) { if ctx.Client == nil { return nil, errors.New("no RPC client defined") } @@ -171,7 +174,7 @@ func (ctx *CLIContext) GetNode() (rpcclient.Client, error) { } // PrintOutput prints output while respecting output and indent flags -func (ctx *CLIContext) PrintOutput(toPrint fmt.Stringer) (err error) { +func (ctx CLIContext) PrintOutput(toPrint fmt.Stringer) (err error) { var out []byte switch ctx.OutputFormat { @@ -195,7 +198,7 @@ func (ctx *CLIContext) PrintOutput(toPrint fmt.Stringer) (err error) { // MessagesOutput respects flags while either generating a transaction // for later signing, or signing and broadcasting those messages in a transaction -func (ctx *CLIContext) MessagesOutput(msgs []sdk.Msg) error { +func (ctx CLIContext) MessagesOutput(msgs []sdk.Msg) error { for _, msg := range msgs { if err := msg.ValidateBasic(); err != nil { return err @@ -211,7 +214,7 @@ func (ctx *CLIContext) MessagesOutput(msgs []sdk.Msg) error { // MessageOutput respects flags while either generating a transaction // for later signing, or signing and broadcasting those messages in a transaction -func (ctx *CLIContext) MessageOutput(msg sdk.Msg) error { +func (ctx CLIContext) MessageOutput(msg sdk.Msg) error { return ctx.MessagesOutput([]sdk.Msg{msg}) } diff --git a/client/context/query.go b/client/context/query.go index 5be354a32204..79d0cd5bcb5b 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -46,7 +46,7 @@ func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sd // error is returned if the query or decoding fails. func (ctx CLIContext) FetchAccount(address []byte) (auth.Account, error) { if ctx.AccDecoder == nil { - ctx.SetAccountDecoder() + ctx.WithAccountDecoder() } res, err := ctx.QueryStore(auth.AddressStoreKey(address), ctx.AccountStore) diff --git a/client/context/tx.go b/client/context/tx.go index 1454c102a724..c23045f13086 100644 --- a/client/context/tx.go +++ b/client/context/tx.go @@ -22,14 +22,14 @@ import ( // supplied messages. Finally, it broadcasts the signed transaction to a node. // // NOTE: Also see CompleteAndBroadcastTxREST. -func (ctx *CLIContext) CompleteAndBroadcastTxCli(msgs []sdk.Msg) error { - err := ctx.PrepareTxBldrWithAddress(ctx.FromAddr()) +func (ctx CLIContext) CompleteAndBroadcastTxCli(msgs []sdk.Msg) error { + ctx, err := ctx.WithTxBldrAddress(ctx.FromAddr()) if err != nil { return err } if ctx.TxBldr.GetSimulateAndExecute() || ctx.Simulate { - err = ctx.EnrichCtxWithGas(ctx.FromName(), msgs) + ctx, err = ctx.EnrichCtxWithGas(ctx.FromName(), msgs) if err != nil { return err } @@ -57,13 +57,13 @@ func (ctx *CLIContext) CompleteAndBroadcastTxCli(msgs []sdk.Msg) error { // EnrichCtxWithGas calculates the gas estimate that would be consumed by the // transaction and set the transaction's respective value accordingly. -func (ctx *CLIContext) EnrichCtxWithGas(name string, msgs []sdk.Msg) error { +func (ctx CLIContext) EnrichCtxWithGas(name string, msgs []sdk.Msg) (CLIContext, error) { _, adjusted, err := ctx.simulateMsgs(name, msgs) if err != nil { - return err + return ctx, err } ctx.TxBldr = ctx.TxBldr.WithGas(adjusted) - return nil + return ctx, nil } // CalculateGas simulates the execution of a transaction and returns @@ -88,7 +88,7 @@ func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), cdc * // PrintUnsignedStdTx builds an unsigned StdTx and prints it to ctx.Ouput. // Don't perform online validation or lookups if offline is true. -func (ctx *CLIContext) PrintUnsignedStdTx(w io.Writer, msgs []sdk.Msg, offline bool) (err error) { +func (ctx CLIContext) PrintUnsignedStdTx(w io.Writer, msgs []sdk.Msg, offline bool) (err error) { var stdTx auth.StdTx @@ -112,7 +112,7 @@ func (ctx *CLIContext) PrintUnsignedStdTx(w io.Writer, msgs []sdk.Msg, offline b // SignStdTx appends a signature to a StdTx and returns a copy of a it. If appendSig // is false, it replaces the signatures already attached with the new signature. // Don't perform online validation or lookups if offline is true. -func (ctx *CLIContext) SignStdTx(name string, stdTx auth.StdTx, appendSig bool, offline bool) (auth.StdTx, error) { +func (ctx CLIContext) SignStdTx(name string, stdTx auth.StdTx, appendSig bool, offline bool) (auth.StdTx, error) { var signedStdTx auth.StdTx keybase, err := keys.GetKeyBase() @@ -133,7 +133,7 @@ func (ctx *CLIContext) SignStdTx(name string, stdTx auth.StdTx, appendSig bool, } if !offline { - err = ctx.PrepareTxBldrWithAddress(addr) + ctx, err = ctx.WithTxBldrAddress(addr) if err != nil { return signedStdTx, err } @@ -150,7 +150,7 @@ func (ctx *CLIContext) SignStdTx(name string, stdTx auth.StdTx, appendSig bool, // SignStdTxWithSignerAddress attaches a signature to a StdTx and returns a copy of a it. // Don't perform online validation or lookups if offline is true, else // populate account and sequence numbers from a foreign account. -func (ctx *CLIContext) SignStdTxWithSignerAddress(addr sdk.AccAddress, +func (ctx CLIContext) SignStdTxWithSignerAddress(addr sdk.AccAddress, name string, stdTx auth.StdTx, offline bool) (signedStdTx auth.StdTx, err error) { // check whether the address is a signer @@ -159,7 +159,7 @@ func (ctx *CLIContext) SignStdTxWithSignerAddress(addr sdk.AccAddress, } if !offline { - err = ctx.PrepareTxBldrWithAddress(addr) + ctx, err = ctx.WithTxBldrAddress(addr) if err != nil { return signedStdTx, err } @@ -185,7 +185,7 @@ func GetTxEncoder(cdc *codec.Codec) (encoder sdk.TxEncoder) { // nolint // SimulateMsgs simulates the transaction and returns the gas estimate and the adjusted value. -func (ctx *CLIContext) simulateMsgs(name string, msgs []sdk.Msg) (uint64, uint64, error) { +func (ctx CLIContext) simulateMsgs(name string, msgs []sdk.Msg) (uint64, uint64, error) { txBytes, err := ctx.TxBldr.BuildWithPubKey(name, msgs) if err != nil { return 0, 0, err @@ -196,19 +196,19 @@ func (ctx *CLIContext) simulateMsgs(name string, msgs []sdk.Msg) (uint64, uint64 // buildUnsignedStdTx builds a StdTx as per the parameters passed in the // contexts. Gas is automatically estimated if gas wanted is set to 0. -func (ctx *CLIContext) buildUnsignedStdTx(msgs []sdk.Msg) (stdTx auth.StdTx, err error) { - err = ctx.PrepareTxBldrWithAddress(ctx.FromAddr()) +func (ctx CLIContext) buildUnsignedStdTx(msgs []sdk.Msg) (stdTx auth.StdTx, err error) { + ctx, err = ctx.WithTxBldrAddress(ctx.FromAddr()) if err != nil { return } return ctx.buildUnsignedStdTxOffline(msgs) } -func (ctx *CLIContext) buildUnsignedStdTxOffline(msgs []sdk.Msg) (stdTx auth.StdTx, err error) { +func (ctx CLIContext) buildUnsignedStdTxOffline(msgs []sdk.Msg) (stdTx auth.StdTx, err error) { if ctx.TxBldr.GetSimulateAndExecute() { var name = ctx.FromName() - err = ctx.EnrichCtxWithGas(name, msgs) + ctx, err = ctx.EnrichCtxWithGas(name, msgs) if err != nil { return } diff --git a/client/lcd/root.go b/client/lcd/root.go index 87da95829d87..6bcb463e9a0c 100644 --- a/client/lcd/root.go +++ b/client/lcd/root.go @@ -28,7 +28,7 @@ import ( // RestServer represents the Light Client Rest server type RestServer struct { Mux *mux.Router - CliCtx *context.CLIContext + CliCtx context.CLIContext KeyBase keybase.Keybase Cdc *codec.Codec @@ -40,7 +40,7 @@ type RestServer struct { // NewRestServer creates a new rest server instance func NewRestServer(cdc *codec.Codec) *RestServer { r := mux.NewRouter() - cliCtx := context.NewCLIContext(cdc).SetAccountDecoder() + cliCtx := context.NewCLIContext(cdc).WithAccountDecoder() logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "rest-server") return &RestServer{ diff --git a/client/rpc/block.go b/client/rpc/block.go index 3371471be4f7..313a9e4a9779 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -52,7 +52,7 @@ func BlockCommand(cdc *codec.Codec) *cobra.Command { return cmd } -func getBlock(cliCtx *context.CLIContext, height *int64) ([]byte, error) { +func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) { // get the node node, err := cliCtx.GetNode() if err != nil { @@ -91,7 +91,7 @@ func getBlock(cliCtx *context.CLIContext, height *int64) ([]byte, error) { } // get the current blockchain height -func GetChainHeight(cliCtx *context.CLIContext) (int64, error) { +func GetChainHeight(cliCtx context.CLIContext) (int64, error) { node, err := cliCtx.GetNode() if err != nil { return -1, err @@ -107,7 +107,7 @@ func GetChainHeight(cliCtx *context.CLIContext) (int64, error) { // REST // REST handler to get a block -func BlockRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { +func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) height, err := strconv.ParseInt(vars["height"], 10, 64) @@ -133,7 +133,7 @@ func BlockRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { } // REST handler to get the latest block -func LatestBlockRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { +func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { height, err := GetChainHeight(cliCtx) if err != nil { diff --git a/client/rpc/root.go b/client/rpc/root.go index d1dde892e70a..cb25b47f31e8 100644 --- a/client/rpc/root.go +++ b/client/rpc/root.go @@ -12,7 +12,7 @@ import ( ) // Register REST endpoints -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) { r.HandleFunc("/version", CLIVersionRequestHandler).Methods("GET") r.HandleFunc("/node_version", NodeVersionRequestHandler(cliCtx)).Methods("GET") r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(cliCtx)).Methods("GET") @@ -30,7 +30,7 @@ func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) { } // connected node version REST handler endpoint -func NodeVersionRequestHandler(cliCtx *context.CLIContext) http.HandlerFunc { +func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { version, err := cliCtx.Query("/app/version", nil) if err != nil { diff --git a/client/rpc/status.go b/client/rpc/status.go index 6702810a21e0..044cd3c2ad8c 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -49,7 +49,7 @@ func StatusCommand(cdc *codec.Codec) *cobra.Command { return cmd } -func getNodeStatus(cliCtx *context.CLIContext) (*ctypes.ResultStatus, error) { +func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) { // get the node node, err := cliCtx.GetNode() if err != nil { @@ -62,7 +62,7 @@ func getNodeStatus(cliCtx *context.CLIContext) (*ctypes.ResultStatus, error) { // REST // REST handler for node info -func NodeInfoRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { +func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { status, err := getNodeStatus(cliCtx) if err != nil { @@ -77,7 +77,7 @@ func NodeInfoRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { } // REST handler for node syncing -func NodeSyncingRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { +func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { status, err := getNodeStatus(cliCtx) if err != nil { diff --git a/client/rpc/validators.go b/client/rpc/validators.go index b90de9b5ec53..08bfbd8a4376 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -85,7 +85,7 @@ func bech32ValidatorOutput(validator *tmtypes.Validator) (ValidatorOutput, error }, nil } -func getValidators(cliCtx *context.CLIContext, height *int64) ([]byte, error) { +func getValidators(cliCtx context.CLIContext, height *int64) ([]byte, error) { // get the node node, err := cliCtx.GetNode() if err != nil { @@ -130,7 +130,7 @@ func getValidators(cliCtx *context.CLIContext, height *int64) ([]byte, error) { // REST // Validator Set at a height REST handler -func ValidatorSetRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { +func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) @@ -159,7 +159,7 @@ func ValidatorSetRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { } // Latest Validator Set REST handler -func LatestValidatorSetRequestHandlerFn(cliCtx *context.CLIContext) http.HandlerFunc { +func LatestValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { height, err := GetChainHeight(cliCtx) if err != nil { diff --git a/client/tx/broadcast.go b/client/tx/broadcast.go index d1b8d85b4f7b..4080b68ec33e 100644 --- a/client/tx/broadcast.go +++ b/client/tx/broadcast.go @@ -27,7 +27,7 @@ type BroadcastBody struct { // BroadcastTxRequest REST Handler // nolint: gocyclo -func BroadcastTxRequest(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var m BroadcastBody body, err := ioutil.ReadAll(r.Body) diff --git a/client/tx/query.go b/client/tx/query.go index e07aa3d79404..34fc916c8123 100644 --- a/client/tx/query.go +++ b/client/tx/query.go @@ -51,7 +51,7 @@ func QueryTxCmd(cdc *codec.Codec) *cobra.Command { return cmd } -func queryTx(cdc *codec.Codec, cliCtx *context.CLIContext, hashHexStr string) ([]byte, error) { +func queryTx(cdc *codec.Codec, cliCtx context.CLIContext, hashHexStr string) ([]byte, error) { hash, err := hex.DecodeString(hashHexStr) if err != nil { return nil, err @@ -86,7 +86,7 @@ func queryTx(cdc *codec.Codec, cliCtx *context.CLIContext, hashHexStr string) ([ } // ValidateTxResult performs transaction verification -func ValidateTxResult(cliCtx *context.CLIContext, res *ctypes.ResultTx) error { +func ValidateTxResult(cliCtx context.CLIContext, res *ctypes.ResultTx) error { check, err := cliCtx.Verify(res.Height) if err != nil { return err @@ -135,7 +135,7 @@ func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { // REST // transaction query REST handler -func QueryTxRequestHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func QueryTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) hashHexStr := vars["hash"] diff --git a/client/tx/root.go b/client/tx/root.go index de84a5d7cb0c..5cd7eca0b8aa 100644 --- a/client/tx/root.go +++ b/client/tx/root.go @@ -8,7 +8,7 @@ import ( ) // register REST routes -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET") r.HandleFunc("/txs", SearchTxRequestHandlerFn(cliCtx, cdc)).Methods("GET") r.HandleFunc("/txs", BroadcastTxRequest(cliCtx, cdc)).Methods("POST") diff --git a/client/tx/search.go b/client/tx/search.go index 511c1eb2a0a1..9dd1092efac8 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -105,7 +105,7 @@ $ gaiacli query txs --tags ':&:' --page 1 --limit 30 // SearchTxs performs a search for transactions for a given set of tags via // Tendermint RPC. It returns a slice of Info object containing txs and metadata. // An error is returned if the query fails. -func SearchTxs(cliCtx *context.CLIContext, cdc *codec.Codec, tags []string, page, limit int) ([]Info, error) { +func SearchTxs(cliCtx context.CLIContext, cdc *codec.Codec, tags []string, page, limit int) ([]Info, error) { if len(tags) == 0 { return nil, errors.New("must declare at least one tag to search") } @@ -168,7 +168,7 @@ func FormatTxResults(cdc *codec.Codec, res []*ctypes.ResultTx) ([]Info, error) { // REST // Search Tx REST Handler -func SearchTxRequestHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var tags []string var page, limit int diff --git a/client/utils/rest.go b/client/utils/rest.go index 27b12bb97cf2..fa21a4a8cfa5 100644 --- a/client/utils/rest.go +++ b/client/utils/rest.go @@ -217,7 +217,7 @@ func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req i // NOTE: Also see CompleteAndBroadcastTxCli. // NOTE: Also see x/stake/client/rest/tx.go delegationsRequestHandlerFn. func CompleteAndBroadcastTxREST( - w http.ResponseWriter, r *http.Request, cliCtx *context.CLIContext, + w http.ResponseWriter, r *http.Request, cliCtx context.CLIContext, baseReq BaseReq, msgs []sdk.Msg, cdc *codec.Codec, ) { @@ -244,7 +244,7 @@ func CompleteAndBroadcastTxREST( return } - if err = cliCtx.EnrichCtxWithGas(baseReq.Name, msgs); err != nil { + if cliCtx, err = cliCtx.EnrichCtxWithGas(baseReq.Name, msgs); err != nil { WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return } diff --git a/cmd/gaia/init/gentx.go b/cmd/gaia/init/gentx.go index f0943108a22b..385e6312eb0f 100644 --- a/cmd/gaia/init/gentx.go +++ b/cmd/gaia/init/gentx.go @@ -109,7 +109,7 @@ following delegation and commission default parameters: // Run gaiad tx create-validator cliCtx := context.NewCLIContextTx(cdc) - msg, err := cli.BuildCreateValidatorMsg(cliCtx) + cliCtx, msg, err := cli.BuildCreateValidatorMsg(cliCtx) if err != nil { return err } diff --git a/x/auth/client/cli/account.go b/x/auth/client/cli/account.go index cc8a664da314..1c4aadf202fe 100644 --- a/x/auth/client/cli/account.go +++ b/x/auth/client/cli/account.go @@ -18,7 +18,7 @@ func GetAccountCmd(storeName string, cdc *codec.Codec) *cobra.Command { Short: "Query account balance", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - cliCtx := context.NewCLIContext(cdc).SetAccountDecoder() + cliCtx := context.NewCLIContext(cdc).WithAccountDecoder() key, err := sdk.AccAddressFromBech32(args[0]) if err != nil { diff --git a/x/auth/client/cli/multisign.go b/x/auth/client/cli/multisign.go index b91f330f25e8..afdf3c6ac9f6 100644 --- a/x/auth/client/cli/multisign.go +++ b/x/auth/client/cli/multisign.go @@ -73,7 +73,7 @@ func makeMultiSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) - cliCtx := context.NewCLIContext(cdc).SetAccountDecoder() + cliCtx := context.NewCLIContext(cdc).WithAccountDecoder() txBldr := authtxb.NewTxBuilderFromCLI() if !viper.GetBool(flagOffline) { diff --git a/x/auth/client/cli/sign.go b/x/auth/client/cli/sign.go index 3680e4dc13e6..3010b6468e98 100644 --- a/x/auth/client/cli/sign.go +++ b/x/auth/client/cli/sign.go @@ -163,7 +163,7 @@ func makeSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) error // its expected signers. In addition, if offline has not been supplied, the // signature is verified over the transaction sign bytes. func printAndValidateSigs( - cliCtx *context.CLIContext, chainID string, stdTx auth.StdTx, offline bool, + cliCtx context.CLIContext, chainID string, stdTx auth.StdTx, offline bool, ) bool { fmt.Println("Signers:") diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 93e9dbe0b637..db0eae584488 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -13,7 +13,7 @@ import ( ) // register REST routes -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, storeName string) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, storeName string) { r.HandleFunc( "/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, cdc, cliCtx.GetAccountDecoder(), cliCtx), @@ -31,7 +31,7 @@ func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, // query accountREST Handler func QueryAccountRequestHandlerFn( storeName string, cdc *codec.Codec, - decoder auth.AccountDecoder, cliCtx *context.CLIContext, + decoder auth.AccountDecoder, cliCtx context.CLIContext, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) @@ -69,7 +69,7 @@ func QueryAccountRequestHandlerFn( // query accountREST Handler func QueryBalancesRequestHandlerFn( storeName string, cdc *codec.Codec, - decoder auth.AccountDecoder, cliCtx *context.CLIContext, + decoder auth.AccountDecoder, cliCtx context.CLIContext, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") diff --git a/x/auth/client/rest/sign.go b/x/auth/client/rest/sign.go index 4a6bc5a1191c..f1af76390cce 100644 --- a/x/auth/client/rest/sign.go +++ b/x/auth/client/rest/sign.go @@ -21,7 +21,7 @@ type SignBody struct { // nolint: unparam // sign tx REST handler -func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var m SignBody diff --git a/x/bank/client/rest/broadcast.go b/x/bank/client/rest/broadcast.go index cba3b8226e5e..71696f12b3c3 100644 --- a/x/bank/client/rest/broadcast.go +++ b/x/bank/client/rest/broadcast.go @@ -15,7 +15,7 @@ type broadcastBody struct { } // BroadcastTxRequestHandlerFn returns the broadcast tx REST handler -func BroadcastTxRequestHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func BroadcastTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var m broadcastBody if ok := unmarshalBodyOrReturnBadRequest(cliCtx, w, r, &m); !ok { @@ -38,7 +38,7 @@ func BroadcastTxRequestHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) h } } -func unmarshalBodyOrReturnBadRequest(cliCtx *context.CLIContext, w http.ResponseWriter, r *http.Request, m *broadcastBody) bool { +func unmarshalBodyOrReturnBadRequest(cliCtx context.CLIContext, w http.ResponseWriter, r *http.Request, m *broadcastBody) bool { body, err := ioutil.ReadAll(r.Body) if err != nil { utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) diff --git a/x/bank/client/rest/sendtx.go b/x/bank/client/rest/sendtx.go index 6b7f84768e6c..d73d7e61e3cb 100644 --- a/x/bank/client/rest/sendtx.go +++ b/x/bank/client/rest/sendtx.go @@ -15,7 +15,7 @@ import ( ) // RegisterRoutes - Central function to define routes that get registered by the main application -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc("/bank/accounts/{address}/transfers", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST") r.HandleFunc("/tx/broadcast", BroadcastTxRequestHandlerFn(cdc, cliCtx)).Methods("POST") } @@ -32,7 +32,7 @@ func init() { } // SendRequestHandlerFn - http request handler to send coins to a address. -func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *context.CLIContext) http.HandlerFunc { +func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) bech32Addr := vars["address"] diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 936eda37dd67..96142941ef07 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -29,7 +29,7 @@ const ( ) // RegisterRoutes - Central function to define routes that get registered by the main application -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc("/gov/proposals", postProposalHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST") @@ -73,7 +73,7 @@ type voteReq struct { Option string `json:"option"` // option from OptionSet chosen by the voter } -func postProposalHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req postProposalReq err := utils.ReadRESTReq(w, r, cdc, &req) @@ -105,7 +105,7 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.Ha } } -func depositHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func depositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -144,7 +144,7 @@ func depositHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.Handler } } -func voteHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -189,7 +189,7 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFun } } -func queryParamsHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) paramType := vars[RestParamsType] @@ -204,7 +204,7 @@ func queryParamsHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.Han } } -func queryProposalHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -238,7 +238,7 @@ func queryProposalHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.H } } -func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -286,7 +286,7 @@ func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.H } } -func queryProposerHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryProposerHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -306,7 +306,7 @@ func queryProposerHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.H } } -func queryDepositHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryDepositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -380,7 +380,7 @@ func queryDepositHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.Ha } } -func queryVoteHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryVoteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -455,7 +455,7 @@ func queryVoteHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.Handl } // todo: Split this functionality into helper functions to remove the above -func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -510,7 +510,7 @@ func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) } // todo: Split this functionality into helper functions to remove the above -func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { bechVoterAddr := r.URL.Query().Get(RestVoter) bechDepositorAddr := r.URL.Query().Get(RestDepositor) @@ -570,7 +570,7 @@ func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx *context.CLIContext) } // todo: Split this functionality into helper functions to remove the above -func queryTallyOnProposalHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryTallyOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index dbacc49784e1..dadd7dd534ee 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -38,7 +38,7 @@ func (p Proposer) String() string { // NOTE: SearchTxs is used to facilitate the txs query which does not currently // support configurable pagination. func QueryDepositsByTxQuery( - cdc *codec.Codec, cliCtx *context.CLIContext, params gov.QueryProposalParams, + cdc *codec.Codec, cliCtx context.CLIContext, params gov.QueryProposalParams, ) ([]byte, error) { tags := []string{ @@ -83,7 +83,7 @@ func QueryDepositsByTxQuery( // NOTE: SearchTxs is used to facilitate the txs query which does not currently // support configurable pagination. func QueryVotesByTxQuery( - cdc *codec.Codec, cliCtx *context.CLIContext, params gov.QueryProposalParams, + cdc *codec.Codec, cliCtx context.CLIContext, params gov.QueryProposalParams, ) ([]byte, error) { tags := []string{ @@ -123,7 +123,7 @@ func QueryVotesByTxQuery( // QueryVoteByTxQuery will query for a single vote via a direct txs tags query. func QueryVoteByTxQuery( - cdc *codec.Codec, cliCtx *context.CLIContext, params gov.QueryVoteParams, + cdc *codec.Codec, cliCtx context.CLIContext, params gov.QueryVoteParams, ) ([]byte, error) { tags := []string{ @@ -166,7 +166,7 @@ func QueryVoteByTxQuery( // QueryDepositByTxQuery will query for a single deposit via a direct txs tags // query. func QueryDepositByTxQuery( - cdc *codec.Codec, cliCtx *context.CLIContext, params gov.QueryDepositParams, + cdc *codec.Codec, cliCtx context.CLIContext, params gov.QueryDepositParams, ) ([]byte, error) { tags := []string{ @@ -209,7 +209,7 @@ func QueryDepositByTxQuery( // QueryProposerByTxQuery will query for a proposer of a governance proposal by // ID. func QueryProposerByTxQuery( - cdc *codec.Codec, cliCtx *context.CLIContext, proposalID uint64, + cdc *codec.Codec, cliCtx context.CLIContext, proposalID uint64, ) (Proposer, error) { tags := []string{ @@ -237,7 +237,7 @@ func QueryProposerByTxQuery( } // QueryProposalByID takes a proposalID and returns a proposal -func QueryProposalByID(proposalID uint64, cliCtx *context.CLIContext, cdc *codec.Codec, queryRoute string) ([]byte, error) { +func QueryProposalByID(proposalID uint64, cliCtx context.CLIContext, cdc *codec.Codec, queryRoute string) ([]byte, error) { params := gov.NewQueryProposalParams(proposalID) bz, err := cdc.MarshalJSON(params) if err != nil { diff --git a/x/ibc/client/cli/relay.go b/x/ibc/client/cli/relay.go index a0295d6452b7..d947b051bed7 100644 --- a/x/ibc/client/cli/relay.go +++ b/x/ibc/client/cli/relay.go @@ -153,12 +153,12 @@ OUTER: } func (c relayCommander) query(node string, key []byte, storeName string) (res []byte, err error) { - return context.NewCLIContext(c.cdc).SetNode(node).QueryStore(key, storeName) + return context.NewCLIContext(c.cdc).WithNode(node).QueryStore(key, storeName) } // nolint: unparam func (c relayCommander) broadcastTx(node string, tx []byte) error { - _, err := context.NewCLIContext(c.cdc).SetNode(node).BroadcastTx(tx) + _, err := context.NewCLIContext(c.cdc).WithNode(node).BroadcastTx(tx) return err } diff --git a/x/ibc/client/rest/transfer.go b/x/ibc/client/rest/transfer.go index ca818b73e778..ab26b6e42046 100644 --- a/x/ibc/client/rest/transfer.go +++ b/x/ibc/client/rest/transfer.go @@ -14,7 +14,7 @@ import ( ) // RegisterRoutes - Central function to define routes that get registered by the main application -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc("/ibc/{destchain}/{address}/send", TransferRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST") } @@ -25,7 +25,7 @@ type transferReq struct { // TransferRequestHandler - http request handler to transfer coins to a address // on a different chain via IBC. -func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *context.CLIContext) http.HandlerFunc { +func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) destChainID := vars["destchain"] diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 1e4d1e35a6ea..59c6493c2352 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing" ) -func registerQueryRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec) { +func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc( "/slashing/validators/{validatorPubKey}/signing_info", signingInfoHandlerFn(cliCtx, slashing.StoreKey, cdc), @@ -27,7 +27,7 @@ func registerQueryRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.C // http request handler to query signing info // nolint: unparam -func signingInfoHandlerFn(cliCtx *context.CLIContext, storeName string, cdc *codec.Codec) http.HandlerFunc { +func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) @@ -62,7 +62,7 @@ func signingInfoHandlerFn(cliCtx *context.CLIContext, storeName string, cdc *cod } } -func queryParamsHandlerFn(cdc *codec.Codec, cliCtx *context.CLIContext) http.HandlerFunc { +func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { route := fmt.Sprintf("custom/%s/parameters", slashing.QuerierRoute) diff --git a/x/slashing/client/rest/rest.go b/x/slashing/client/rest/rest.go index d60457aba4c8..507fcb517fc4 100644 --- a/x/slashing/client/rest/rest.go +++ b/x/slashing/client/rest/rest.go @@ -9,7 +9,7 @@ import ( ) // RegisterRoutes registers staking-related REST handlers to a router -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { registerQueryRoutes(cliCtx, r, cdc) registerTxRoutes(cliCtx, r, cdc, kb) } diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 5ff145a5c81d..add8c6665bee 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -14,7 +14,7 @@ import ( "github.com/gorilla/mux" ) -func registerTxRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { +func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc( "/slashing/validators/{validatorAddr}/unjail", unjailRequestHandlerFn(cdc, kb, cliCtx), @@ -26,7 +26,7 @@ type UnjailReq struct { BaseReq utils.BaseReq `json:"base_req"` } -func unjailRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *context.CLIContext) http.HandlerFunc { +func unjailRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 1e29f069baa8..4350398bbb5d 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -21,7 +21,7 @@ func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContextTx(cdc) - msg, err := BuildCreateValidatorMsg(cliCtx) + cliCtx, msg, err := BuildCreateValidatorMsg(cliCtx) if err != nil { return err } @@ -193,17 +193,17 @@ func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command { } // BuildCreateValidatorMsg makes a new MsgCreateValidator. -func BuildCreateValidatorMsg(cliCtx *context.CLIContext) (sdk.Msg, error) { +func BuildCreateValidatorMsg(cliCtx context.CLIContext) (context.CLIContext, sdk.Msg, error) { amounstStr := viper.GetString(FlagAmount) amount, err := sdk.ParseCoin(amounstStr) if err != nil { - return nil, err + return cliCtx, nil, err } pkStr := viper.GetString(FlagPubKey) pk, err := sdk.GetConsPubKeyBech32(pkStr) if err != nil { - return nil, err + return cliCtx, nil, err } description := staking.NewDescription( @@ -219,7 +219,7 @@ func BuildCreateValidatorMsg(cliCtx *context.CLIContext) (sdk.Msg, error) { maxChangeRateStr := viper.GetString(FlagCommissionMaxChangeRate) commissionMsg, err := buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr) if err != nil { - return nil, err + return cliCtx, nil, err } delAddr := viper.GetString(FlagAddressDelegator) @@ -228,7 +228,7 @@ func BuildCreateValidatorMsg(cliCtx *context.CLIContext) (sdk.Msg, error) { if delAddr != "" { delAddr, err := sdk.AccAddressFromBech32(delAddr) if err != nil { - return nil, err + return cliCtx, nil, err } msg = staking.NewMsgCreateValidatorOnBehalfOf( @@ -244,8 +244,8 @@ func BuildCreateValidatorMsg(cliCtx *context.CLIContext) (sdk.Msg, error) { ip := viper.GetString(FlagIP) nodeID := viper.GetString(FlagNodeID) if nodeID != "" && ip != "" { - cliCtx.TxBldr = cliCtx.TxBldr.WithMemo(fmt.Sprintf("%s@%s:26656", nodeID, ip)) + cliCtx = cliCtx.WithMemo(fmt.Sprintf("%s@%s:26656", nodeID, ip)) } } - return msg, nil + return cliCtx, msg, nil } diff --git a/x/staking/client/cli/utils.go b/x/staking/client/cli/utils.go index f374c2a3c3f6..a606723908ba 100644 --- a/x/staking/client/cli/utils.go +++ b/x/staking/client/cli/utils.go @@ -43,7 +43,7 @@ func getShares( // make a query to get the existing delegation shares key := staking.GetDelegationKey(delAddr, valAddr) - cliCtx := context.NewCLIContext(cdc).SetAccountDecoder() + cliCtx := context.NewCLIContext(cdc).WithAccountDecoder() resQuery, err := cliCtx.QueryStore(key, storeName) if err != nil { diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index cef31fad3121..c51f9e7ad0ac 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -15,7 +15,7 @@ import ( "github.com/gorilla/mux" ) -func registerQueryRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec) { +func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { // Get all delegations from a delegator r.HandleFunc( @@ -104,17 +104,17 @@ func registerQueryRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.C } // HTTP request handler to query a delegator delegations -func delegatorDelegationsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func delegatorDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryDelegator(cliCtx, cdc, "custom/staking/delegatorDelegations") } // HTTP request handler to query a delegator unbonding delegations -func delegatorUnbondingDelegationsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func delegatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryDelegator(cliCtx, cdc, "custom/staking/delegatorUnbondingDelegations") } // HTTP request handler to query all staking txs (msgs) from a delegator -func delegatorTxsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var typesQuerySlice []string vars := mux.Vars(r) @@ -185,12 +185,12 @@ func delegatorTxsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.Ha } // HTTP request handler to query an unbonding-delegation -func unbondingDelegationHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func unbondingDelegationHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryBonds(cliCtx, cdc, "custom/staking/unbondingDelegation") } // HTTP request handler to query redelegations -func redelegationsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func redelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var params staking.QueryRedelegationParams @@ -241,22 +241,22 @@ func redelegationsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.H } // HTTP request handler to query a delegation -func delegationHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func delegationHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryBonds(cliCtx, cdc, "custom/staking/delegation") } // HTTP request handler to query all delegator bonded validators -func delegatorValidatorsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryDelegator(cliCtx, cdc, "custom/staking/delegatorValidators") } // HTTP request handler to get information from a currently bonded validator -func delegatorValidatorHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryBonds(cliCtx, cdc, "custom/staking/delegatorValidator") } // HTTP request handler to query list of validators -func validatorsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { res, err := cliCtx.QueryWithData("custom/staking/validators", nil) if err != nil { @@ -268,22 +268,22 @@ func validatorsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.Hand } // HTTP request handler to query the validator information from a given validator address -func validatorHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func validatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryValidator(cliCtx, cdc, "custom/staking/validator") } // HTTP request handler to query all unbonding delegations from a validator -func validatorDelegationsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func validatorDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryValidator(cliCtx, cdc, "custom/staking/validatorDelegations") } // HTTP request handler to query all unbonding delegations from a validator -func validatorUnbondingDelegationsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return queryValidator(cliCtx, cdc, "custom/staking/validatorUnbondingDelegations") } // HTTP request handler to query the pool information -func poolHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func poolHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { res, err := cliCtx.QueryWithData("custom/staking/pool", nil) if err != nil { @@ -295,7 +295,7 @@ func poolHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFun } // HTTP request handler to query the staking params values -func paramsHandlerFn(cliCtx *context.CLIContext, cdc *codec.Codec) http.HandlerFunc { +func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { res, err := cliCtx.QueryWithData("custom/staking/parameters", nil) if err != nil { diff --git a/x/staking/client/rest/rest.go b/x/staking/client/rest/rest.go index d60457aba4c8..507fcb517fc4 100644 --- a/x/staking/client/rest/rest.go +++ b/x/staking/client/rest/rest.go @@ -9,7 +9,7 @@ import ( ) // RegisterRoutes registers staking-related REST handlers to a router -func RegisterRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { registerQueryRoutes(cliCtx, r, cdc) registerTxRoutes(cliCtx, r, cdc, kb) } diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index c6867edc1be2..73d86ce423fa 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -14,7 +14,7 @@ import ( "github.com/gorilla/mux" ) -func registerTxRoutes(cliCtx *context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { +func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc( "/staking/delegators/{delegatorAddr}/delegations", postDelegationsHandlerFn(cdc, kb, cliCtx), @@ -53,7 +53,7 @@ type ( } ) -func postDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *context.CLIContext) http.HandlerFunc { +func postDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req msgDelegationsInput @@ -90,7 +90,7 @@ func postDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *context } } -func postRedelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *context.CLIContext) http.HandlerFunc { +func postRedelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req msgBeginRedelegateInput @@ -127,7 +127,7 @@ func postRedelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *conte } } -func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx *context.CLIContext) http.HandlerFunc { +func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req msgUndelegateInput diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index bcbcbe9b1f46..2a95776e3dc0 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -28,7 +28,7 @@ func contains(stringSlice []string, txType string) bool { } // queries staking txs -func queryTxs(node rpcclient.Client, cliCtx *context.CLIContext, cdc *codec.Codec, tag string, delegatorAddr string) ([]tx.Info, error) { +func queryTxs(node rpcclient.Client, cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegatorAddr string) ([]tx.Info, error) { page := 0 perPage := 100 prove := !cliCtx.TrustNode @@ -50,7 +50,7 @@ func queryTxs(node rpcclient.Client, cliCtx *context.CLIContext, cdc *codec.Code return tx.FormatTxResults(cdc, res.Txs) } -func queryRedelegations(cliCtx *context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { +func queryRedelegations(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] @@ -94,7 +94,7 @@ func queryRedelegations(cliCtx *context.CLIContext, cdc *codec.Codec, endpoint s } } -func queryBonds(cliCtx *context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { +func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] @@ -124,7 +124,7 @@ func queryBonds(cliCtx *context.CLIContext, cdc *codec.Codec, endpoint string) h } } -func queryDelegator(cliCtx *context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { +func queryDelegator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] @@ -152,7 +152,7 @@ func queryDelegator(cliCtx *context.CLIContext, cdc *codec.Codec, endpoint strin } } -func queryValidator(cliCtx *context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { +func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) bech32validatorAddr := vars["validatorAddr"]