prysm-pulse/tools/faucet/server.go
Preston Van Loon 81c2e4e94b
First pass on pow faucet for testnet (#1624)
* first pass on pow faucet for testnet

* delete unused thing

* remove unneeded thing

*  remove other thing

* https & remove a log

* don't force redirect on https, its not working?

* some renaming of stuff

* lint

* lint

* some stablity config

* move protos to proto directory, add generated pb file for go users

* add health probe

* add hpa and request cpu

* handle err

* some more config
2019-02-19 12:32:14 -05:00

45 lines
1.1 KiB
Go

package main
import (
"context"
"errors"
"fmt"
recaptcha "github.com/prestonvanloon/go-recaptcha"
faucetpb "github.com/prysmaticlabs/prysm/proto/faucet"
"google.golang.org/grpc/peer"
)
var minScore = 0.5
type faucetServer struct {
r recaptcha.Recaptcha
}
// RequestFunds from the ethereum 1.x faucet. Requires a valid captcha
// response.
func (s *faucetServer) RequestFunds(ctx context.Context, req *faucetpb.FundingRequest) (*faucetpb.FundingResponse, error) {
p, ok := peer.FromContext(ctx)
if !ok {
return nil, errors.New("peer from ctx not ok")
}
fmt.Printf("Sending captcha request for peer %s\n", p.Addr.String())
rr, err := s.r.Check(p.Addr.String(), req.RecaptchaResponse)
if err != nil {
return nil, err
}
if !rr.Success {
fmt.Printf("Unsuccessful recaptcha request. Error codes: %+v\n", rr.ErrorCodes)
return &faucetpb.FundingResponse{Error: "Recaptcha failed"}, nil
}
if rr.Score < minScore {
return &faucetpb.FundingResponse{Error: "Recaptcha score too low"}, nil
}
return &faucetpb.FundingResponse{
Amount: "500000000000000000",
TransactionHash: "0xfake",
}, nil
}