Skip to content

Commit

Permalink
refactor: rename the flags regarding the faucet
Browse files Browse the repository at this point in the history
  • Loading branch information
iczc committed Mar 15, 2022
1 parent c30c8b5 commit 75c6cb8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: bin/eth-faucet -httpport $PORT -interval 30 -proxycount 1
web: bin/eth-faucet -httpport $PORT -proxycount 1 -faucet.minutes 30
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export PRIVATE_KEY="hex private key"

**Optional Flags**

| Flag | Description | Default Value
| ----------- | ------------------------------------------------ | -------------
| -chainname | Network name to display on the frontend | testnet
| -httpport | Listener port to serve HTTP connection | 8080
| -interval | Number of minutes to wait between funding rounds | 1440
| -payout | Number of Ethers to transfer per user request | 1
| -proxycount | Count of reverse proxies in front of the server | 0
| -queuecap | Maximum transactions waiting to be sent | 100
| Flag | Description | Default Value
| -------------- | ------------------------------------------------ | -------------
| -httpport | Listener port to serve HTTP connection | 8080
| -proxycount | Count of reverse proxies in front of the server | 0
| -queuecap | Maximum transactions waiting to be sent | 100
| -faucet.amount | Number of Ethers to transfer per user request | 1
| -faucet.minutes| Number of minutes to wait between funding rounds | 1440
| -faucet.name | Network name to display on the frontend | testnet

### Docker deployment

Expand Down
27 changes: 14 additions & 13 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@ import (
)

const (
AppVersion = "v1.0.0"
DefaultKeyAuth = "password.txt"
)

var chainIDMap = map[string]int{"mainnet": 1, "ropsten": 3, "rinkeby": 4, "goerli": 5, "kovan": 42}

var (
chainNameFlag = flag.String("chainname", "testnet", "Network name to display on the frontend")
httpPortFlag = flag.Int("httpport", 8080, "Listener port to serve HTTP connection")
intervalFlag = flag.Int("interval", 1440, "Number of minutes to wait between funding rounds")
payoutFlag = flag.Int("payout", 1, "Number of Ethers to transfer per user request")
proxyCntFlag = flag.Int("proxycount", 0, "Count of reverse proxies in front of the server")
queueCapFlag = flag.Int("queuecap", 100, "Maximum transactions waiting to be sent")
versionFlag = flag.Bool("v", false, "Print version number")
appVersion = "v1.0.0"
chainIDMap = map[string]int{"ropsten": 3, "rinkeby": 4, "goerli": 5, "kovan": 42}

httpPortFlag = flag.Int("httpport", 8080, "Listener port to serve HTTP connection")
proxyCntFlag = flag.Int("proxycount", 0, "Count of reverse proxies in front of the server")
queueCapFlag = flag.Int("queuecap", 100, "Maximum transactions waiting to be sent")
versionFlag = flag.Bool("version", false, "Print version number")

payoutFlag = flag.Int("faucet.amount", 1, "Number of Ethers to transfer per user request")
intervalFlag = flag.Int("faucet.minutes", 1440, "Number of minutes to wait between funding rounds")
netnameFlag = flag.String("faucet.name", "testnet", "Network name to display on the frontend")
)

func init() {
flag.Parse()
if *versionFlag {
fmt.Println(AppVersion)
fmt.Println(appVersion)
os.Exit(0)
}
}
Expand All @@ -46,15 +47,15 @@ func Execute() {
panic(fmt.Errorf("failed to read private key: %w", err))
}
var chainID *big.Int
if value, ok := chainIDMap[strings.ToLower(*chainNameFlag)]; ok {
if value, ok := chainIDMap[strings.ToLower(*netnameFlag)]; ok {
chainID = big.NewInt(int64(value))
}

txBuilder, err := chain.NewTxBuilder(os.Getenv("WEB3_PROVIDER"), privateKey, chainID)
if err != nil {
panic(fmt.Errorf("cannot connect to web3 provider: %w", err))
}
config := server.NewConfig(*chainNameFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *queueCapFlag)
config := server.NewConfig(*netnameFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *queueCapFlag)
go server.NewServer(txBuilder, config).Run()

c := make(chan os.Signal, 1)
Expand Down
6 changes: 3 additions & 3 deletions internal/server/config.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package server

type Config struct {
chainName string
network string
httpPort int
interval int
payout int
proxyCount int
queueCap int
}

func NewConfig(chainName string, httpPort, interval, payout, proxyCount, queueCap int) *Config {
func NewConfig(network string, httpPort, interval, payout, proxyCount, queueCap int) *Config {
return &Config{
chainName: chainName,
network: network,
httpPort: httpPort,
interval: interval,
payout: payout,
Expand Down
12 changes: 6 additions & 6 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func (s *Server) handleClaim() http.HandlerFunc {

func (s *Server) handleInfo() http.HandlerFunc {
type info struct {
Account string `json:"account"`
ChainName string `json:"network"`
Payout string `json:"payout"`
Account string `json:"account"`
Network string `json:"network"`
Payout string `json:"payout"`
}
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
Expand All @@ -134,9 +134,9 @@ func (s *Server) handleInfo() http.HandlerFunc {

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(info{
Account: s.Sender().String(),
ChainName: s.cfg.chainName,
Payout: strconv.Itoa(s.cfg.payout),
Account: s.Sender().String(),
Network: s.cfg.network,
Payout: strconv.Itoa(s.cfg.payout),
})
}
}

0 comments on commit 75c6cb8

Please sign in to comment.