Skip to content

Commit

Permalink
Use go-sequencer-client (#1)
Browse files Browse the repository at this point in the history
* use go-sequencer-client

* we no longer need the chain id

* remove cruft

* renaming

* removing crufty test

* updates after using new version of go-sequencer-client

* comment

* update readme

* use ed25519 instead of ecdsa. remove the keystore bc it uses ecdsa.

* fix return type for Transfer function

* use correct version of go-sequencer-client

* remove funding

* add label to dockerfile so it connects to repo

* use correct name for docker image. only build on merges to main and new tags.

* remove comment

* fix how we convert the amount to uint128
  • Loading branch information
steezeburger authored Sep 27, 2023
1 parent 8426706 commit bc0f861
Show file tree
Hide file tree
Showing 12 changed files with 2,997 additions and 352 deletions.
13 changes: 0 additions & 13 deletions .github/FUNDING.yml

This file was deleted.

17 changes: 6 additions & 11 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
name: Build and Publish Docker image

# Trigger on pushes to astria branch, new semantic version tags, and pull request updates
# Trigger on pushes to main branch and new semantic version tags
on:
workflow_dispatch:
push:
branches:
- "astria"
- "main"
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"
# trigger on pull request updates when target is `astria` branch
pull_request:
branches:
- "astria"

jobs:
build-and-publish-latest:
Expand Down Expand Up @@ -47,22 +43,21 @@ jobs:
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/astriaorg/ria-faucet
ghcr.io/astriaorg/seq-faucet
tags: |
type=ref,event=pr
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=sha
# set latest tag for `astria` branch
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'astria') }}
# set latest tag for `main` branch
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Build and push
uses: docker/build-push-action@v4
with:
# this gets rid of the unknown/unknown image that is created without this setting
# https://github.com/docker/build-push-action/issues/820#issuecomment-1455687416
provenance: false
context: .
# It takes a long time to build the arm image right now, so we only build it on tags which is what we use for releases, or on merges to the default branch.
platforms: ${{ (contains(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/astria') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM node:lts-alpine as frontend
LABEL org.opencontainers.image.source https://github.com/astriaorg/seq-faucet

WORKDIR /frontend-build

Expand Down
30 changes: 5 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The faucet is a web application with the goal of distributing small amounts of E

## Features

* Allow to configure the funding account via private key or keystore
* Allow to configure the funding account via private key
* Asynchronous processing Txs to achieve parallel execution of user requests
* Rate limiting by ETH address and IP address as a precaution against spam
* Prevent X-Forwarded-For spoofing by specifying the count of reverse proxies
Expand Down Expand Up @@ -46,31 +46,17 @@ go build -o seq-faucet
**Use private key to fund users**

```bash
./seq-faucet -httpport 8080 -wallet.provider http://localhost:8545 -wallet.privkey privkey
```

**Use keystore to fund users**

```bash
./seq-faucet -httpport 8080 -wallet.provider http://localhost:8545 -wallet.keyjson keystore -wallet.keypass password.txt
./seq-faucet -wallet.provider tcp://sequencer.localdev.me:80 -wallet.privkey privkey
```

### Configuration

You can configure the funder by using environment variables instead of command-line flags as follows:
```bash
export WEB3_PROVIDER=https://some.rpc.endpoint
export WEB3_PROVIDER=tcp://sequencer.localdev.me:80
export PRIVATE_KEY=0x...
```

or

```bash
export WEB3_PROVIDER=https://some.rpc.endpoint
export KEYSTORE=path/to/keystore
echo "your keystore password" > `pwd`/password.txt
```

Then run the faucet application without the wallet command-line flags:
```bash
./seq-faucet -httpport 8080
Expand All @@ -92,19 +78,13 @@ The following are the available command-line flags(excluding above wallet flags)
### Docker deployment

```bash
docker run -d -p 8080:8080 -e WEB3_PROVIDER=https://some.rpc.endpoint -e PRIVATE_KEY=0x... astriaorg/seq-faucet:1.1.0
```

or

```bash
docker run -d -p 8080:8080 -e WEB3_PROVIDER=https://some.rpc.endpoint -e KEYSTORE=path/to/keystore -v `pwd`/keystore:/app/keystore -v `pwd`/password.txt:/app/password.txt astriaorg/seq-faucet:1.1.0
docker run -d -p 8080:8080 -e WEB3_PROVIDER=tcp://sequencer.localdev.me:80 -e PRIVATE_KEY=0x... astriaorg/seq-faucet:1.1.0
```

#### Build the Docker image

```bash
docker buildx build -t ghcr.io/astriaorg/astria-faucet:0.0.1-local .
docker buildx build -t ghcr.io/astriaorg/seq-faucet:0.0.1-local .
```

## License
Expand Down
42 changes: 14 additions & 28 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package cmd

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

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

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

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

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,8 +25,6 @@ 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")
)
Expand All @@ -44,16 +38,12 @@ func init() {
}

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

txBuilder, err := chain.NewTxBuilder(*providerFlag, privateKey, chainID)
txBuilder, err := chain.NewTxBuilder(*providerFlag, privateKey)
if err != nil {
panic(fmt.Errorf("cannot connect to web3 provider: %w", err))
}
Expand All @@ -65,25 +55,21 @@ func Execute() {
<-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")
func getPrivateKeyFromFlag() (*ed25519.PrivateKey, error) {
if *privKeyFlag == "" {
return nil, errors.New("no private key provided")
}

keyfile, err := chain.ResolveKeyfilePath(*keyJSONFlag)
if err != nil {
return nil, err
hexkey := *privKeyFlag
if chain.Has0xPrefix(hexkey) {
hexkey = hexkey[2:]
}
password, err := os.ReadFile(*keyPassFlag)

privateKeyBytes, err := hex.DecodeString(hexkey)
if err != nil {
return nil, err
}

return chain.DecryptKeyfile(keyfile, strings.TrimRight(string(password), "\r\n"))
privateKey := ed25519.PrivateKey(privateKeyBytes)
return &privateKey, nil
}
40 changes: 32 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,63 @@ go 1.17
require (
github.com/LK4D4/trylock v0.0.0-20191027065348-ff7e133a5c54
github.com/agiledragon/gomonkey/v2 v2.9.0
github.com/astriaorg/go-sequencer-client v0.0.0-20230926140906-b52311b219a1
github.com/ethereum/go-ethereum v1.10.26
github.com/jellydator/ttlcache/v2 v2.11.1
github.com/sirupsen/logrus v1.8.1
github.com/sirupsen/logrus v1.9.0
github.com/urfave/negroni v1.0.0
)

require (
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/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cometbft/cometbft v0.37.0 // indirect
github.com/cosmos/gogoproto v1.4.1 // 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-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.0 // 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/gorilla/websocket v1.4.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
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
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
google.golang.org/grpc v1.52.0 // indirect
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
)
Loading

0 comments on commit bc0f861

Please sign in to comment.