forked from cerc-io/laconicd-deprecated
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user