* Refactor CliContext as Context
* Fix lint issues
* Fix goimports
* Fix gov tests
* Resolved ci-lint issues
* Add changelog
* Rename cliCtx to clientCtx
* Fix mocks and routes
* Add changelog
* Update changelog
* Apply suggestions from code review
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
* merge client/rpc/ro{ot,utes}.go
* Update docs
* client/rpc: remove redundant client/rpc.RegisterRPCRoutes
* regenerate mocks
* Update ADRs
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package client
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
)
|
|
|
|
// WriteGenerateStdTxResponse writes response for the generate only mode.
|
|
func WriteGenerateStdTxResponse(w http.ResponseWriter, clientCtx client.Context, br rest.BaseReq, msgs []sdk.Msg) {
|
|
gasAdj, ok := rest.ParseFloat64OrReturnBadRequest(w, br.GasAdjustment, flags.DefaultGasAdjustment)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
simAndExec, gas, err := flags.ParseGas(br.Gas)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
|
|
txBldr := types.NewTxBuilder(
|
|
GetTxEncoder(clientCtx.Codec), br.AccountNumber, br.Sequence, gas, gasAdj,
|
|
br.Simulate, br.ChainID, br.Memo, br.Fees, br.GasPrices,
|
|
)
|
|
|
|
if br.Simulate || simAndExec {
|
|
if gasAdj < 0 {
|
|
rest.WriteErrorResponse(w, http.StatusBadRequest, errors.ErrorInvalidGasAdjustment.Error())
|
|
return
|
|
}
|
|
|
|
txBldr, err = EnrichWithGas(txBldr, clientCtx, msgs)
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
|
|
if br.Simulate {
|
|
rest.WriteSimulationResponse(w, clientCtx.Codec, txBldr.Gas())
|
|
return
|
|
}
|
|
}
|
|
|
|
stdMsg, err := txBldr.BuildSignMsg(msgs)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
|
|
output, err := clientCtx.Codec.MarshalJSON(types.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo))
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
if _, err := w.Write(output); err != nil {
|
|
log.Printf("could not write response: %v", err)
|
|
}
|
|
|
|
}
|