update init script (#309)

* update init script

* rename faucet cmd
This commit is contained in:
Federico Kunze
2020-05-20 17:29:26 -04:00
committed by GitHub
parent 50ddf9ae73
commit 5d15be6adb
3 changed files with 29 additions and 21 deletions
+5 -5
View File
@@ -27,17 +27,17 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
}
faucetTxCmd.AddCommand(flags.PostCommands(
GetCmdFund(cdc),
GetCmdRequest(cdc),
)...)
return faucetTxCmd
}
// GetCmdFund is the CLI command to fund an address with the requested coins
func GetCmdFund(cdc *codec.Codec) *cobra.Command {
// GetCmdRequest is the CLI command to fund an address with the requested coins
func GetCmdRequest(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "fund [amount] [other-recipient (optional)]",
Short: "fund an address with the requested coins",
Use: "request [amount] [other-recipient (optional)]",
Short: "request an address with the requested coins",
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
+5 -5
View File
@@ -16,20 +16,20 @@ import (
// RegisterRoutes register REST endpoints for the faucet module
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/%s/fund", types.ModuleName), fundHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/request", types.ModuleName), requestHandler(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/funded", types.ModuleName), fundedHandlerFn(cliCtx)).Methods("GET")
}
// PostFundRequest defines fund request's body.
type PostFundRequest struct {
// PostRequestBody defines fund request's body.
type PostRequestBody struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Amount sdk.Coins `json:"amount" yaml:"amount"`
Recipient string `json:"receipient" yaml:"receipient"`
}
func fundHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
func requestHandler(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req PostFundRequest
var req PostRequestBody
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request")
return