Skip to content

chore(faucet): compliency gno/faucet and gnoweb #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ var errInvalidBeneficiary = errors.New("invalid beneficiary address")

// defaultHTTPHandler is the default faucet transfer handler
func (f *Faucet) defaultHTTPHandler(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
http.Error(w, "invalid request body", http.StatusBadRequest)

return
}
Comment on lines +24 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: you can inline this

if err := r.ParseForm(); err != nil {
    http.Error(w, "invalid request body", http.StatusBadRequest)

    return
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't put it like that to avoid redefine err lower, but i'm fine for adding a var err error :)


// Load the requests
requestBody, readErr := io.ReadAll(r.Body)
if readErr != nil {
Expand All @@ -29,16 +36,24 @@ func (f *Faucet) defaultHTTPHandler(w http.ResponseWriter, r *http.Request) {
return
}

// Extract the requests
requests, err := extractRequests(requestBody)
if err != nil {
http.Error(
w,
"invalid request body",
http.StatusBadRequest,
)
var requests Requests

return
if to := r.FormValue("toaddr"); to != "" {
requests = Requests{
{To: to},
}
Comment on lines +41 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like the fact we are modelling the behavior of a generic TM2 faucet based on gnoweb (and exact field names in gnoweb. The faucet is envisioned to work through POST requests of a specific format (or we can define our own handlers, endpoints, the faucet lib allows for that).

We are deprecating the old gno faucet anyways, so might as well make the change now.

I propose we take one of these routes:

  • modify gnoweb to send a POST with a standard body that is expected in this faucet implementation, this way only 1 thing is changed, and it's on the Gnoweb side (easy route, and longterm the final version, since we are deprecating the old faucet)
  • use this faucet as a lib in gno, and extend the faucet to have specific handlers / routes you would use for gnoweb (define custom handlers, like we did for gnochess). This option is less favorable, because it just introduces complexity we'd drop later on when deleting the old faucet

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% ok with this, i just choose a quicker solution for having a fix to work with

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the "form" system is an easier system for the way we're using gno/templating html

} else {
// Extract the requests
requests, err = extractRequests(requestBody)
if err != nil {
http.Error(
w,
"invalid request body",
http.StatusBadRequest,
)

return
}
}

// Handle the requests
Expand Down