Don't use pointers when you need them not!
This commit is contained in:
parent
1370ca611b
commit
122ed3a900
|
@ -12,16 +12,16 @@ const (
|
||||||
|
|
||||||
// WriteErrorResponse prepares and writes a HTTP error
|
// WriteErrorResponse prepares and writes a HTTP error
|
||||||
// given a status code and an error message.
|
// given a status code and an error message.
|
||||||
func WriteErrorResponse(w *http.ResponseWriter, status int, msg string) {
|
func WriteErrorResponse(w http.ResponseWriter, status int, msg string) {
|
||||||
(*w).WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
(*w).Write([]byte(msg))
|
w.Write([]byte(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteGasEstimateResponse prepares and writes an HTTP
|
// WriteGasEstimateResponse prepares and writes an HTTP
|
||||||
// response for transactions simulations.
|
// response for transactions simulations.
|
||||||
func WriteSimulationResponse(w *http.ResponseWriter, gas int64) {
|
func WriteSimulationResponse(w http.ResponseWriter, gas int64) {
|
||||||
(*w).WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
(*w).Write([]byte(fmt.Sprintf(`{"gas_estimate":%v}`, gas)))
|
w.Write([]byte(fmt.Sprintf(`{"gas_estimate":%v}`, gas)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasDryRunArg returns true if the request's URL query contains
|
// HasDryRunArg returns true if the request's URL query contains
|
||||||
|
@ -32,7 +32,7 @@ func HasDryRunArg(r *http.Request) bool {
|
||||||
|
|
||||||
// ParseFloat64OrReturnBadRequest converts s to a float64 value. It returns a default
|
// ParseFloat64OrReturnBadRequest converts s to a float64 value. It returns a default
|
||||||
// value if the string is empty. Write
|
// value if the string is empty. Write
|
||||||
func ParseFloat64OrReturnBadRequest(w *http.ResponseWriter, s string, defaultIfEmpty float64) (n float64, ok bool) {
|
func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEmpty float64) (n float64, ok bool) {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return defaultIfEmpty, true
|
return defaultIfEmpty, true
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,13 +33,13 @@ func QueryAccountRequestHandlerFn(
|
||||||
|
|
||||||
addr, err := sdk.AccAddressFromBech32(bech32addr)
|
addr, err := sdk.AccAddressFromBech32(bech32addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.QueryStore(auth.AddressStoreKey(addr), storeName)
|
res, err := cliCtx.QueryStore(auth.AddressStoreKey(addr), storeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("couldn't query account. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("couldn't query account. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,14 +52,14 @@ func QueryAccountRequestHandlerFn(
|
||||||
// decode the value
|
// decode the value
|
||||||
account, err := decoder(res)
|
account, err := decoder(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("couldn't parse query result. Result: %s. Error: %s", res, err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("couldn't parse query result. Result: %s. Error: %s", res, err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// print out whole account
|
// print out whole account
|
||||||
output, err := cdc.MarshalJSON(account)
|
output, err := cdc.MarshalJSON(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("couldn't marshall query result. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("couldn't marshall query result. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,32 +51,32 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo
|
||||||
|
|
||||||
to, err := sdk.AccAddressFromBech32(bech32addr)
|
to, err := sdk.AccAddressFromBech32(bech32addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var m sendBody
|
var m sendBody
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = msgCdc.UnmarshalJSON(body, &m)
|
err = msgCdc.UnmarshalJSON(body, &m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := kb.Get(m.LocalAccountName)
|
info, err := kb.Get(m.LocalAccountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, err.Error())
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// build message
|
// build message
|
||||||
msg := client.BuildMsg(sdk.AccAddress(info.GetPubKey().Address()), to, m.Amount)
|
msg := client.BuildMsg(sdk.AccAddress(info.GetPubKey().Address()), to, m.Amount)
|
||||||
if err != nil { // XXX rechecking same error ?
|
if err != nil { // XXX rechecking same error ?
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo
|
||||||
Sequence: m.Sequence,
|
Sequence: m.Sequence,
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(&w, m.GasAdjustment, cliclient.DefaultGasAdjustment)
|
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(w, m.GasAdjustment, cliclient.DefaultGasAdjustment)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -97,11 +97,11 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo
|
||||||
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
||||||
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if utils.HasDryRunArg(r) {
|
if utils.HasDryRunArg(r) {
|
||||||
utils.WriteSimulationResponse(&w, txCtx.Gas)
|
utils.WriteSimulationResponse(w, txCtx.Gas)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txCtx = newCtx
|
txCtx = newCtx
|
||||||
|
@ -109,19 +109,19 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo
|
||||||
|
|
||||||
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, err.Error())
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.BroadcastTx(txBytes)
|
res, err := cliCtx.BroadcastTx(txBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := wire.MarshalJSONIndent(cdc, res)
|
output, err := wire.MarshalJSONIndent(cdc, res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ func postProposalHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.Hand
|
||||||
msg := gov.NewMsgSubmitProposal(req.Title, req.Description, req.ProposalType, req.Proposer, req.InitialDeposit)
|
msg := gov.NewMsgSubmitProposal(req.Title, req.Description, req.ProposalType, req.Proposer, req.InitialDeposit)
|
||||||
err = msg.ValidateBasic()
|
err = msg.ValidateBasic()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ func depositHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFu
|
||||||
|
|
||||||
if len(strProposalID) == 0 {
|
if len(strProposalID) == 0 {
|
||||||
err := errors.New("proposalId required but not specified")
|
err := errors.New("proposalId required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ func depositHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFu
|
||||||
msg := gov.NewMsgDeposit(req.Depositer, proposalID, req.Amount)
|
msg := gov.NewMsgDeposit(req.Depositer, proposalID, req.Amount)
|
||||||
err = msg.ValidateBasic()
|
err = msg.ValidateBasic()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ func voteHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc
|
||||||
|
|
||||||
if len(strProposalID) == 0 {
|
if len(strProposalID) == 0 {
|
||||||
err := errors.New("proposalId required but not specified")
|
err := errors.New("proposalId required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ func voteHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc
|
||||||
msg := gov.NewMsgVote(req.Voter, proposalID, req.Option)
|
msg := gov.NewMsgVote(req.Voter, proposalID, req.Option)
|
||||||
err = msg.ValidateBasic()
|
err = msg.ValidateBasic()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ func queryProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
if len(strProposalID) == 0 {
|
if len(strProposalID) == 0 {
|
||||||
err := errors.New("proposalId required but not specified")
|
err := errors.New("proposalId required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,13 +183,13 @@ func queryProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.QueryWithData("custom/gov/proposal", bz)
|
res, err := cliCtx.QueryWithData("custom/gov/proposal", bz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
if len(strProposalID) == 0 {
|
if len(strProposalID) == 0 {
|
||||||
err := errors.New("proposalId required but not specified")
|
err := errors.New("proposalId required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,14 +216,14 @@ func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
if len(bechDepositerAddr) == 0 {
|
if len(bechDepositerAddr) == 0 {
|
||||||
err := errors.New("depositer address required but not specified")
|
err := errors.New("depositer address required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
depositerAddr, err := sdk.AccAddressFromBech32(bechDepositerAddr)
|
depositerAddr, err := sdk.AccAddressFromBech32(bechDepositerAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := errors.Errorf("'%s' needs to be bech32 encoded", RestDepositer)
|
err := errors.Errorf("'%s' needs to be bech32 encoded", RestDepositer)
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,13 +236,13 @@ func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.QueryWithData("custom/gov/deposit", bz)
|
res, err := cliCtx.QueryWithData("custom/gov/deposit", bz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,11 +252,11 @@ func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
res, err := cliCtx.QueryWithData("custom/gov/proposal", cdc.MustMarshalBinary(gov.QueryProposalParams{params.ProposalID}))
|
res, err := cliCtx.QueryWithData("custom/gov/proposal", cdc.MustMarshalBinary(gov.QueryProposalParams{params.ProposalID}))
|
||||||
if err != nil || len(res) == 0 {
|
if err != nil || len(res) == 0 {
|
||||||
err := errors.Errorf("proposalID [%d] does not exist", proposalID)
|
err := errors.Errorf("proposalID [%d] does not exist", proposalID)
|
||||||
utils.WriteErrorResponse(&w, http.StatusNotFound, err.Error())
|
utils.WriteErrorResponse(w, http.StatusNotFound, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = errors.Errorf("depositer [%s] did not deposit on proposalID [%d]", bechDepositerAddr, proposalID)
|
err = errors.Errorf("depositer [%s] did not deposit on proposalID [%d]", bechDepositerAddr, proposalID)
|
||||||
utils.WriteErrorResponse(&w, http.StatusNotFound, err.Error())
|
utils.WriteErrorResponse(w, http.StatusNotFound, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
if len(strProposalID) == 0 {
|
if len(strProposalID) == 0 {
|
||||||
err := errors.New("proposalId required but not specified")
|
err := errors.New("proposalId required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,14 +283,14 @@ func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
if len(bechVoterAddr) == 0 {
|
if len(bechVoterAddr) == 0 {
|
||||||
err := errors.New("voter address required but not specified")
|
err := errors.New("voter address required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr)
|
voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := errors.Errorf("'%s' needs to be bech32 encoded", RestVoter)
|
err := errors.Errorf("'%s' needs to be bech32 encoded", RestVoter)
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,13 +302,13 @@ func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.QueryWithData("custom/gov/vote", bz)
|
res, err := cliCtx.QueryWithData("custom/gov/vote", bz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,17 +317,17 @@ func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
if vote.Empty() {
|
if vote.Empty() {
|
||||||
bz, err := cdc.MarshalJSON(gov.QueryProposalParams{params.ProposalID})
|
bz, err := cdc.MarshalJSON(gov.QueryProposalParams{params.ProposalID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res, err := cliCtx.QueryWithData("custom/gov/proposal", bz)
|
res, err := cliCtx.QueryWithData("custom/gov/proposal", bz)
|
||||||
if err != nil || len(res) == 0 {
|
if err != nil || len(res) == 0 {
|
||||||
err := errors.Errorf("proposalID [%d] does not exist", proposalID)
|
err := errors.Errorf("proposalID [%d] does not exist", proposalID)
|
||||||
utils.WriteErrorResponse(&w, http.StatusNotFound, err.Error())
|
utils.WriteErrorResponse(w, http.StatusNotFound, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = errors.Errorf("voter [%s] did not deposit on proposalID [%d]", bechVoterAddr, proposalID)
|
err = errors.Errorf("voter [%s] did not deposit on proposalID [%d]", bechVoterAddr, proposalID)
|
||||||
utils.WriteErrorResponse(&w, http.StatusNotFound, err.Error())
|
utils.WriteErrorResponse(w, http.StatusNotFound, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(res)
|
w.Write(res)
|
||||||
|
@ -343,7 +343,7 @@ func queryVotesOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
if len(strProposalID) == 0 {
|
if len(strProposalID) == 0 {
|
||||||
err := errors.New("proposalId required but not specified")
|
err := errors.New("proposalId required but not specified")
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,13 +359,13 @@ func queryVotesOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.QueryWithData("custom/gov/votes", bz)
|
res, err := cliCtx.QueryWithData("custom/gov/votes", bz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr)
|
voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := errors.Errorf("'%s' needs to be bech32 encoded", RestVoter)
|
err := errors.Errorf("'%s' needs to be bech32 encoded", RestVoter)
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
params.Voter = voterAddr
|
params.Voter = voterAddr
|
||||||
|
@ -398,7 +398,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
depositerAddr, err := sdk.AccAddressFromBech32(bechDepositerAddr)
|
depositerAddr, err := sdk.AccAddressFromBech32(bechDepositerAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := errors.Errorf("'%s' needs to be bech32 encoded", RestDepositer)
|
err := errors.Errorf("'%s' needs to be bech32 encoded", RestDepositer)
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
params.Depositer = depositerAddr
|
params.Depositer = depositerAddr
|
||||||
|
@ -408,7 +408,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
proposalStatus, err := gov.ProposalStatusFromString(strProposalStatus)
|
proposalStatus, err := gov.ProposalStatusFromString(strProposalStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := errors.Errorf("'%s' is not a valid Proposal Status", strProposalStatus)
|
err := errors.Errorf("'%s' is not a valid Proposal Status", strProposalStatus)
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
params.ProposalStatus = proposalStatus
|
params.ProposalStatus = proposalStatus
|
||||||
|
@ -423,7 +423,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc {
|
||||||
|
|
||||||
res, err := cliCtx.QueryWithData("custom/gov/proposals", bz)
|
res, err := cliCtx.QueryWithData("custom/gov/proposals", bz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,12 @@ type baseReq struct {
|
||||||
func buildReq(w http.ResponseWriter, r *http.Request, cdc *wire.Codec, req interface{}) error {
|
func buildReq(w http.ResponseWriter, r *http.Request, cdc *wire.Codec, req interface{}) error {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = cdc.UnmarshalJSON(body, req)
|
err = cdc.UnmarshalJSON(body, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -40,27 +40,27 @@ func buildReq(w http.ResponseWriter, r *http.Request, cdc *wire.Codec, req inter
|
||||||
|
|
||||||
func (req baseReq) baseReqValidate(w http.ResponseWriter) bool {
|
func (req baseReq) baseReqValidate(w http.ResponseWriter) bool {
|
||||||
if len(req.Name) == 0 {
|
if len(req.Name) == 0 {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Name required but not specified")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Name required but not specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.Password) == 0 {
|
if len(req.Password) == 0 {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Password required but not specified")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Password required but not specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.ChainID) == 0 {
|
if len(req.ChainID) == 0 {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "ChainID required but not specified")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "ChainID required but not specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.AccountNumber < 0 {
|
if req.AccountNumber < 0 {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Account Number required but not specified")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Account Number required but not specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Sequence < 0 {
|
if req.Sequence < 0 {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Sequence required but not specified")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Sequence required but not specified")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -78,7 +78,7 @@ func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLICont
|
||||||
Gas: baseReq.Gas,
|
Gas: baseReq.Gas,
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(&w, baseReq.GasAdjustment, client.DefaultGasAdjustment)
|
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(w, baseReq.GasAdjustment, client.DefaultGasAdjustment)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -87,30 +87,30 @@ func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLICont
|
||||||
if utils.HasDryRunArg(r) || baseReq.Gas == 0 {
|
if utils.HasDryRunArg(r) || baseReq.Gas == 0 {
|
||||||
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, baseReq.Name, []sdk.Msg{msg})
|
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, baseReq.Name, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if utils.HasDryRunArg(r) {
|
if utils.HasDryRunArg(r) {
|
||||||
utils.WriteSimulationResponse(&w, txCtx.Gas)
|
utils.WriteSimulationResponse(w, txCtx.Gas)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txCtx = newCtx
|
txCtx = newCtx
|
||||||
}
|
}
|
||||||
txBytes, err := txCtx.BuildAndSign(baseReq.Name, baseReq.Password, []sdk.Msg{msg})
|
txBytes, err := txCtx.BuildAndSign(baseReq.Name, baseReq.Password, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, err.Error())
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.BroadcastTx(txBytes)
|
res, err := cliCtx.BroadcastTx(txBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := wire.MarshalJSONIndent(cdc, res)
|
output, err := wire.MarshalJSONIndent(cdc, res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,26 +44,26 @@ func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.C
|
||||||
|
|
||||||
to, err := sdk.AccAddressFromBech32(bech32addr)
|
to, err := sdk.AccAddressFromBech32(bech32addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var m transferBody
|
var m transferBody
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cdc.UnmarshalJSON(body, &m)
|
err = cdc.UnmarshalJSON(body, &m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := kb.Get(m.LocalAccountName)
|
info, err := kb.Get(m.LocalAccountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, err.Error())
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.C
|
||||||
Gas: m.Gas,
|
Gas: m.Gas,
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(&w, m.GasAdjustment, client.DefaultGasAdjustment)
|
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(w, m.GasAdjustment, client.DefaultGasAdjustment)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -88,11 +88,11 @@ func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.C
|
||||||
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
||||||
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if utils.HasDryRunArg(r) {
|
if utils.HasDryRunArg(r) {
|
||||||
utils.WriteSimulationResponse(&w, txCtx.Gas)
|
utils.WriteSimulationResponse(w, txCtx.Gas)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txCtx = newCtx
|
txCtx = newCtx
|
||||||
|
@ -100,19 +100,19 @@ func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.C
|
||||||
|
|
||||||
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, err.Error())
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.BroadcastTx(txBytes)
|
res, err := cliCtx.BroadcastTx(txBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := cdc.MarshalJSON(res)
|
output, err := cdc.MarshalJSON(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,29 +44,29 @@ func unjailRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLI
|
||||||
var m UnjailBody
|
var m UnjailBody
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &m)
|
err = json.Unmarshal(body, &m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusBadRequest, err.Error())
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := kb.Get(m.LocalAccountName)
|
info, err := kb.Get(m.LocalAccountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, err.Error())
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valAddr, err := sdk.ValAddressFromBech32(m.ValidatorAddr)
|
valAddr, err := sdk.ValAddressFromBech32(m.ValidatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(info.GetPubKey().Address(), valAddr) {
|
if !bytes.Equal(info.GetPubKey().Address(), valAddr) {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Must use own validator address")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Must use own validator address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ func unjailRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLI
|
||||||
|
|
||||||
msg := slashing.NewMsgUnjail(valAddr)
|
msg := slashing.NewMsgUnjail(valAddr)
|
||||||
|
|
||||||
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(&w, m.GasAdjustment, client.DefaultGasAdjustment)
|
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(w, m.GasAdjustment, client.DefaultGasAdjustment)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,11 @@ func unjailRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLI
|
||||||
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
||||||
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if utils.HasDryRunArg(r) {
|
if utils.HasDryRunArg(r) {
|
||||||
utils.WriteSimulationResponse(&w, txCtx.Gas)
|
utils.WriteSimulationResponse(w, txCtx.Gas)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txCtx = newCtx
|
txCtx = newCtx
|
||||||
|
@ -101,19 +101,19 @@ func unjailRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLI
|
||||||
|
|
||||||
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Must use own validator address")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Must use own validator address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cliCtx.BroadcastTx(txBytes)
|
res, err := cliCtx.BroadcastTx(txBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := json.MarshalIndent(res, "", " ")
|
output, err := json.MarshalIndent(res, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,18 +108,18 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
for _, msg := range m.Delegations {
|
for _, msg := range m.Delegations {
|
||||||
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddr)
|
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Must use own delegator address")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Must use own delegator address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,29 +135,29 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
for _, msg := range m.BeginRedelegates {
|
for _, msg := range m.BeginRedelegates {
|
||||||
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Must use own delegator address")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Must use own delegator address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valSrcAddr, err := sdk.ValAddressFromBech32(msg.ValidatorSrcAddr)
|
valSrcAddr, err := sdk.ValAddressFromBech32(msg.ValidatorSrcAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
valDstAddr, err := sdk.ValAddressFromBech32(msg.ValidatorDstAddr)
|
valDstAddr, err := sdk.ValAddressFromBech32(msg.ValidatorDstAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
shares, err := sdk.NewDecFromStr(msg.SharesAmount)
|
shares, err := sdk.NewDecFromStr(msg.SharesAmount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode shares amount. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode shares amount. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,24 +174,24 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
for _, msg := range m.CompleteRedelegates {
|
for _, msg := range m.CompleteRedelegates {
|
||||||
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valSrcAddr, err := sdk.ValAddressFromBech32(msg.ValidatorSrcAddr)
|
valSrcAddr, err := sdk.ValAddressFromBech32(msg.ValidatorSrcAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valDstAddr, err := sdk.ValAddressFromBech32(msg.ValidatorDstAddr)
|
valDstAddr, err := sdk.ValAddressFromBech32(msg.ValidatorDstAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Must use own delegator address")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Must use own delegator address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,24 +207,24 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
for _, msg := range m.BeginUnbondings {
|
for _, msg := range m.BeginUnbondings {
|
||||||
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Must use own delegator address")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Must use own delegator address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddr)
|
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
shares, err := sdk.NewDecFromStr(msg.SharesAmount)
|
shares, err := sdk.NewDecFromStr(msg.SharesAmount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode shares amount. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode shares amount. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,18 +240,18 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
for _, msg := range m.CompleteUnbondings {
|
for _, msg := range m.CompleteUnbondings {
|
||||||
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddr)
|
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
if !bytes.Equal(info.GetPubKey().Address(), delAddr) {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, "Must use own delegator address")
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, "Must use own delegator address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
|
|
||||||
m.Sequence++
|
m.Sequence++
|
||||||
|
|
||||||
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(&w, m.GasAdjustment, client.DefaultGasAdjustment)
|
adjustment, ok := utils.ParseFloat64OrReturnBadRequest(w, m.GasAdjustment, client.DefaultGasAdjustment)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -287,11 +287,11 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
if utils.HasDryRunArg(r) || m.Gas == 0 {
|
||||||
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
newCtx, err := utils.EnrichCtxWithGas(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if utils.HasDryRunArg(r) {
|
if utils.HasDryRunArg(r) {
|
||||||
utils.WriteSimulationResponse(&w, txCtx.Gas)
|
utils.WriteSimulationResponse(w, txCtx.Gas)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txCtx = newCtx
|
txCtx = newCtx
|
||||||
|
@ -299,7 +299,7 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
|
|
||||||
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusUnauthorized, err.Error())
|
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
for i, txBytes := range signedTxs {
|
for i, txBytes := range signedTxs {
|
||||||
res, err := cliCtx.BroadcastTx(txBytes)
|
res, err := cliCtx.BroadcastTx(txBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||||
|
|
||||||
output, err := wire.MarshalJSONIndent(cdc, results[:])
|
output, err := wire.MarshalJSONIndent(cdc, results[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.WriteErrorResponse(&w, http.StatusInternalServerError, err.Error())
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue