Skip to content

Commit

Permalink
all: migrate go-bindata to embed (ethereum#24744)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Jan 20, 2025
1 parent 3e02384 commit 30c4bf4
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 1,073 deletions.
1 change: 0 additions & 1 deletion build/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package tools
import (
// Tool imports for go:generate.
_ "github.com/fjl/gencodec"
_ "github.com/kevinburke/go-bindata/go-bindata"
_ "golang.org/x/tools/cmd/stringer"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
)
14 changes: 5 additions & 9 deletions cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
// faucet is a Ether faucet backed by a light client.
package main

//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -o website.go faucet.html
//go:generate gofmt -w -s website.go

import (
"bytes"
"context"
_ "embed"
"encoding/json"
"errors"
"flag"
Expand Down Expand Up @@ -91,6 +89,9 @@ var (
ether = new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)
)

//go:embed faucet.html
var websiteTmpl string

func main() {
// Parse the flags and set up the logger to print everything requested
flag.Parse()
Expand Down Expand Up @@ -122,13 +123,8 @@ func main() {
periods[i] = strings.TrimSuffix(periods[i], "s")
}
}
// Load up and render the faucet website
tmpl, err := Asset("faucet.html")
if err != nil {
log.Crit("Failed to load the faucet template", "err", err)
}
website := new(bytes.Buffer)
err = template.Must(template.New("").Parse(string(tmpl))).Execute(website, map[string]interface{}{
err := template.Must(template.New("").Parse(websiteTmpl)).Execute(website, map[string]interface{}{
"Network": *netnameFlag,
"Amounts": amounts,
"Periods": periods,
Expand Down
275 changes: 0 additions & 275 deletions cmd/faucet/website.go

This file was deleted.

6 changes: 2 additions & 4 deletions console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,10 @@ func (c *Console) initConsoleObject() {
}

func (c *Console) initWeb3(bridge *bridge) error {
bnJS := string(deps.MustAsset("bignumber.js"))
web3JS := string(deps.MustAsset("web3.js"))
if err := c.jsre.Compile("bignumber.js", bnJS); err != nil {
if err := c.jsre.Compile("bignumber.js", deps.BigNumberJS); err != nil {
return fmt.Errorf("bignumber.js: %v", err)
}
if err := c.jsre.Compile("web3.js", web3JS); err != nil {
if err := c.jsre.Compile("web3.js", deps.Web3JS); err != nil {
return fmt.Errorf("web3.js: %v", err)
}
if _, err := c.jsre.Run("var Web3 = require('web3');"); err != nil {
Expand Down
503 changes: 0 additions & 503 deletions eth/tracers/internal/tracers/assets.go

This file was deleted.

8 changes: 5 additions & 3 deletions eth/tracers/internal/tracers/tracers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -o assets.go -pkg tracers -ignore tracers.go -ignore assets.go ./...
//go:generate gofmt -s -w assets.go

// Package tracers contains the actual JavaScript tracer assets.
package tracers

import "embed"

//go:embed *.js
var FS embed.FS
22 changes: 18 additions & 4 deletions eth/tracers/tracers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tracers

import (
"encoding/json"
"io/fs"
"strings"
"unicode"

Expand Down Expand Up @@ -77,9 +78,22 @@ func camel(str string) string {

// init retrieves the JavaScript transaction tracers included in go-ethereum.
func init() {
for _, file := range tracers.AssetNames() {
name := camel(strings.TrimSuffix(file, ".js"))
jsTracers[name] = string(tracers.MustAsset(file))

err := fs.WalkDir(tracers.FS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
b, err := fs.ReadFile(tracers.FS, path)
if err != nil {
return err
}
name := camel(strings.TrimSuffix(path, ".js"))
jsTracers[name] = string(b)
return nil
})
if err != nil {
panic(err)
}
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ require (
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/influxdata/influxdb-client-go/v2 v2.4.0
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
github.com/kevinburke/go-bindata v3.23.0+incompatible
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-isatty v0.0.17
github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4d
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/karalabe/hid v1.0.0 h1:+/CIMNXhSU/zIJgnIvBD2nKHxS/bnRHhhs9xBryLpPo=
github.com/karalabe/hid v1.0.0/go.mod h1:Vr51f8rUOLYrfrWDFlV12GGQgM5AT8sVh+2fY4MPeu8=
github.com/kevinburke/go-bindata v3.23.0+incompatible h1:rqNOXZlqrYhMVVAsQx8wuc+LaA73YcfbQ407wAykyS8=
github.com/kevinburke/go-bindata v3.23.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4=
github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
269 changes: 0 additions & 269 deletions internal/jsre/deps/bindata.go

This file was deleted.

11 changes: 9 additions & 2 deletions internal/jsre/deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
// Package deps contains the console JavaScript dependencies Go embedded.
package deps

//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -pkg deps -o bindata.go bignumber.js web3.js
//go:generate gofmt -w -s bindata.go
import (
_ "embed"
)

//go:embed web3.js
var Web3JS string

//go:embed bignumber.js
var BigNumberJS string

0 comments on commit 30c4bf4

Please sign in to comment.