rpc, evm: refactor (#588)

* stargate: refactor

* remove evm CLI

* rpc: refactor

* more fixes

* fixes fixes fixes

* changelog

* refactor according to namespaces

* fix

* lint

* remove export logic

* fix rpc test

* godoc
This commit is contained in:
Federico Kunze
2020-10-22 17:39:51 -03:00
committed by GitHub
parent be09a6ee1b
commit 4501bbccdc
36 changed files with 2396 additions and 2587 deletions
+4 -4
View File
@@ -37,17 +37,17 @@ func GetCmdFunded(cdc *codec.Codec) *cobra.Command {
Short: "Gets storage for an account at a given key",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
clientCtx := context.NewCLIContext().WithCodec(cdc)
res, height, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryFunded))
res, height, err := clientCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryFunded))
if err != nil {
return err
}
var out sdk.Coins
cdc.MustUnmarshalJSON(res, &out)
cliCtx = cliCtx.WithHeight(height)
return cliCtx.PrintOutput(out)
clientCtx = clientCtx.WithHeight(height)
return clientCtx.PrintOutput(out)
},
}
}
+4 -4
View File
@@ -41,7 +41,7 @@ func GetCmdRequest(cdc *codec.Codec) *cobra.Command {
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
cliCtx := context.NewCLIContext().WithCodec(cdc)
clientCtx := context.NewCLIContext().WithCodec(cdc)
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
amount, err := sdk.ParseCoins(args[0])
@@ -51,7 +51,7 @@ func GetCmdRequest(cdc *codec.Codec) *cobra.Command {
var recipient sdk.AccAddress
if len(args) == 1 {
recipient = cliCtx.GetFromAddress()
recipient = clientCtx.GetFromAddress()
} else {
recipient, err = sdk.AccAddressFromBech32(args[1])
}
@@ -60,12 +60,12 @@ func GetCmdRequest(cdc *codec.Codec) *cobra.Command {
return err
}
msg := types.NewMsgFund(amount, cliCtx.GetFromAddress(), recipient)
msg := types.NewMsgFund(amount, clientCtx.GetFromAddress(), recipient)
if err := msg.ValidateBasic(); err != nil {
return err
}
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
},
}
}
+10 -10
View File
@@ -15,9 +15,9 @@ import (
)
// RegisterRoutes register REST endpoints for the faucet module
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/%s/request", types.ModuleName), requestHandler(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/funded", types.ModuleName), fundedHandlerFn(cliCtx)).Methods("GET")
func RegisterRoutes(clientCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/%s/request", types.ModuleName), requestHandler(clientCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/funded", types.ModuleName), fundedHandlerFn(clientCtx)).Methods("GET")
}
// PostRequestBody defines fund request's body.
@@ -27,10 +27,10 @@ type PostRequestBody struct {
Recipient string `json:"receipient" yaml:"receipient"`
}
func requestHandler(cliCtx context.CLIContext) http.HandlerFunc {
func requestHandler(clientCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req PostRequestBody
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
if !rest.ReadRESTReq(w, r, clientCtx.Codec, &req) {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request")
return
}
@@ -65,19 +65,19 @@ func requestHandler(cliCtx context.CLIContext) http.HandlerFunc {
return
}
authclient.WriteGenerateStdTxResponse(w, cliCtx, baseReq, []sdk.Msg{msg})
authclient.WriteGenerateStdTxResponse(w, clientCtx, baseReq, []sdk.Msg{msg})
}
}
func fundedHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
func fundedHandlerFn(clientCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, _ *http.Request) {
res, height, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryFunded))
res, height, err := clientCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryFunded))
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
clientCtx = clientCtx.WithHeight(height)
rest.PostProcessResponse(w, clientCtx, res)
}
}