Skip to content

Commit

Permalink
remove wallet provider and priv key flags. add store. update request …
Browse files Browse the repository at this point in the history
…shape.
  • Loading branch information
steezeburger committed Jan 18, 2024
1 parent 67d4ea3 commit 254b949
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 88 deletions.
57 changes: 10 additions & 47 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package cmd

import (
"crypto/ecdsa"
"errors"
"flag"
"fmt"
"math/big"
"os"
"os/signal"
"strings"

"github.com/ethereum/go-ethereum/crypto"

"github.com/astriaorg/eth-faucet/internal/chain"
"github.com/astriaorg/eth-faucet/internal/server"
"github.com/astriaorg/eth-faucet/internal/store"
)

var (
appVersion = "v1.1.0"
chainIDMap = map[string]int{"goerli": 5, "sepolia": 11155111}
appVersion = "v2.0.0"

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")
Expand All @@ -29,10 +22,7 @@ var (
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")

keyJSONFlag = flag.String("wallet.keyjson", os.Getenv("KEYSTORE"), "Keystore file to fund user requests with")
keyPassFlag = flag.String("wallet.keypass", "password.txt", "Passphrase text file to decrypt keystore")
privKeyFlag = flag.String("wallet.privkey", os.Getenv("PRIVATE_KEY"), "Private key hex to fund user requests with")
providerFlag = flag.String("wallet.provider", os.Getenv("WEB3_PROVIDER"), "Endpoint for Ethereum JSON-RPC connection")
firestoreProjectID = flag.String("firestoreprojectid", "some-proj-id", "The Firestore project id.")
)

func init() {
Expand All @@ -44,46 +34,19 @@ func init() {
}

func Execute() {
privateKey, err := getPrivateKeyFromFlags()
if err != nil {
panic(fmt.Errorf("failed to read private key: %w", err))
smOpts := &store.NewManagerOpts{
ProjectID: *firestoreProjectID,
}
var chainID *big.Int
if value, ok := chainIDMap[strings.ToLower(*netnameFlag)]; ok {
chainID = big.NewInt(int64(value))
}

txBuilder, err := chain.NewTxBuilder(*providerFlag, privateKey, chainID)
sm, err := store.NewStoreManager(smOpts)
if err != nil {
panic(fmt.Errorf("cannot connect to web3 provider: %w", err))
fmt.Printf("Failed to create store manager: %v\n", err)
os.Exit(1)
}

config := server.NewConfig(*netnameFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *queueCapFlag)
go server.NewServer(txBuilder, config).Run()
go server.NewServer(sm, config).Run()

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
}

func getPrivateKeyFromFlags() (*ecdsa.PrivateKey, error) {
if *privKeyFlag != "" {
hexkey := *privKeyFlag
if chain.Has0xPrefix(hexkey) {
hexkey = hexkey[2:]
}
return crypto.HexToECDSA(hexkey)
} else if *keyJSONFlag == "" {
return nil, errors.New("missing private key or keystore")
}

keyfile, err := chain.ResolveKeyfilePath(*keyJSONFlag)
if err != nil {
return nil, err
}
password, err := os.ReadFile(*keyPassFlag)
if err != nil {
return nil, err
}

return chain.DecryptKeyfile(keyfile, strings.TrimRight(string(password), "\r\n"))
}
34 changes: 29 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/astriaorg/eth-faucet
go 1.21

require (
cloud.google.com/go/firestore v1.14.0
github.com/LK4D4/trylock v0.0.0-20191027065348-ff7e133a5c54
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/ethereum/go-ethereum v1.10.26
Expand All @@ -12,17 +13,27 @@ require (
)

require (
cloud.google.com/go v0.110.2 // indirect
cloud.google.com/go/compute v1.19.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.0 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.4 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
Expand All @@ -36,8 +47,21 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.128.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.56.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
)
Loading

0 comments on commit 254b949

Please sign in to comment.