Skip to content

Commit

Permalink
Setup config (stackup-wallet#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim-j authored Oct 11, 2022
1 parent bfd84d4 commit 9cf1cdb
Show file tree
Hide file tree
Showing 14 changed files with 722 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .air-rpc.toml → .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/rpc"
cmd = "go build -o ./tmp/rpc cmd/rpc.go"
bin = ";ERC4337_BUNDLER_GIN_MODE=debug ./tmp/stackup-bundler"
cmd = "go build -o ./tmp/stackup-bundler main.go"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
# misc
.DS_Store
tmp
.env
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
setup-dev:
install-dev:
go install github.com/cosmtrek/air@latest
go mod tidy

dev-rpc:
air -c .air-rpc.toml
generate-environment:
go run ./cmd/genenv

fetch-wallet:
go run ./cmd/fetchwallet

dev:
air
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ See the `Client` documentation at [docs.stackup.sh](https://docs.stackup.sh/docs
## Setup

```bash
# Will install https://github.com/cosmtrek/air for live reloading
make setup-dev
# Installs https://github.com/cosmtrek/air for live reloading.
# Runs go mod tidy.
make install-dev

# Generates base .env file.
# All variables in this file are required and should be filled.
# Running this command WILL override current .env file.
make generate-environment

# Parses private key in .env file and prints public key and address.
make fetch-wallet
```

## Run RPC server

```bash
make dev-rpc
make dev
```

# License
Expand Down
21 changes: 21 additions & 0 deletions cmd/fetchwallet/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"fmt"

"github.com/spf13/viper"
"github.com/stackup-wallet/stackup-bundler/internal/wallet"
)

func main() {
viper.SetConfigName(".env")
viper.SetConfigType("env")
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}

w := wallet.New(viper.GetString("erc4337_bundler_private_key"))
fmt.Printf("Public key: %s\n", w.PublicKey)
fmt.Printf("Address: %s\n", w.Address)
}
33 changes: 33 additions & 0 deletions cmd/genenv/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Use this for generating a new private key saved to .privatekey
// Implementation from https://goethereumbook.org/en/wallet-generate/
package main

import (
"fmt"
"log"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/spf13/viper"
)

func genPrivateKey() string {
privateKey, err := crypto.GenerateKey()
if err != nil {
log.Fatal(err)
}
privateKeyBytes := crypto.FromECDSA(privateKey)

return hexutil.Encode(privateKeyBytes)[2:]
}

func main() {
viper.SetConfigName(".env")
viper.SetConfigType("env")
viper.Set("ERC4337_BUNDLER_RPC_URL", "")
viper.Set("ERC4337_BUNDLER_PRIVATE_KEY", genPrivateKey())

if err := viper.WriteConfigAs(".env"); err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}
}
48 changes: 0 additions & 48 deletions cmd/rpc.go

This file was deleted.

21 changes: 18 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
module github.com/stackup-wallet/standalone-bundler
module github.com/stackup-wallet/stackup-bundler

go 1.19

require (
github.com/ethereum/go-ethereum v1.10.25
github.com/gin-gonic/gin v1.8.1
github.com/iancoleman/strcase v0.2.0
github.com/spf13/viper v1.13.0
golang.org/x/text v0.3.7
)

require (
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 9cf1cdb

Please sign in to comment.