diff --git a/Makefile b/Makefile index 5d8137bb15de..d8ac4232201d 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,6 @@ clean: devtools: env GOBIN= go install golang.org/x/tools/cmd/stringer@latest - env GOBIN= go install github.com/kevinburke/go-bindata/go-bindata@latest env GOBIN= go install github.com/fjl/gencodec@latest env GOBIN= go install github.com/golang/protobuf/protoc-gen-go@latest env GOBIN= go install ./cmd/abigen diff --git a/build/tools/tools.go b/build/tools/tools.go index 69b1c3f8445c..fd2681a28b37 100644 --- a/build/tools/tools.go +++ b/build/tools/tools.go @@ -23,7 +23,6 @@ import ( // Tool imports for go:generate. _ "github.com/fjl/gencodec" _ "github.com/golang/protobuf/protoc-gen-go" - _ "github.com/kevinburke/go-bindata/go-bindata" _ "golang.org/x/tools/cmd/stringer" // Tool imports for mobile build. diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 641dd2aa87d8..bcf28bd584d0 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -17,12 +17,10 @@ // faucet is an 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" @@ -99,6 +97,9 @@ var ( gitDate = "" // Git commit date YYYYMMDD of the release (set via linker flags) ) +//go:embed faucet.html +var websiteTmpl string + func main() { // Parse the flags and set up the logger to print everything requested flag.Parse() @@ -130,13 +131,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, diff --git a/console/console.go b/console/console.go index f1995557c5b0..ecf2764520d1 100644 --- a/console/console.go +++ b/console/console.go @@ -182,12 +182,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 { diff --git a/eth/tracers/js/internal/tracers/tracers.go b/eth/tracers/js/internal/tracers/tracers.go index 785962b1d6c3..5a416d30e55b 100644 --- a/eth/tracers/js/internal/tracers/tracers.go +++ b/eth/tracers/js/internal/tracers/tracers.go @@ -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 . -//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 diff --git a/eth/tracers/js/tracer.go b/eth/tracers/js/tracer.go index a71d2920ffaa..dd68e52bd0f3 100644 --- a/eth/tracers/js/tracer.go +++ b/eth/tracers/js/tracer.go @@ -14,13 +14,14 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -// package js is a collection of tracers written in javascript. +// Package js is a collection of tracers written in javascript. package js import ( "encoding/json" "errors" "fmt" + "io/fs" "math/big" "strings" "sync/atomic" @@ -51,9 +52,23 @@ var assetTracers = make(map[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")) - assetTracers[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")) + assetTracers[name] = string(b) + return nil + }) + if err != nil { + panic(err) } tracers2.RegisterLookup(true, newJsTracer) } @@ -685,7 +700,7 @@ func (jst *jsTracer) CaptureTxStart(gasLimit uint64) { jst.gasLimit = gasLimit } -// CaptureTxStart implements the Tracer interface and is invoked at the end of +// CaptureTxEnd implements the Tracer interface and is invoked at the end of // transaction processing. func (*jsTracer) CaptureTxEnd(restGas uint64) {} diff --git a/go.mod b/go.mod index 307adb71bd1f..1ceed81faf23 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,6 @@ require ( github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e github.com/julienschmidt/httprouter v1.3.0 github.com/karalabe/usb v0.0.2 - github.com/kevinburke/go-bindata v3.23.0+incompatible github.com/kylelemons/godebug v1.1.0 // indirect github.com/mattn/go-colorable v0.1.8 github.com/mattn/go-isatty v0.0.12 diff --git a/go.sum b/go.sum index 0212f23a6c46..0f5676f49641 100644 --- a/go.sum +++ b/go.sum @@ -360,8 +360,6 @@ github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0= github.com/karalabe/usb v0.0.2 h1:M6QQBNxF+CQ8OFvxrT90BA0qBOXymndZnk5q235mFc4= github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= -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/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= diff --git a/internal/jsre/deps/deps.go b/internal/jsre/deps/deps.go index e7af4685164b..42af8f77e0de 100644 --- a/internal/jsre/deps/deps.go +++ b/internal/jsre/deps/deps.go @@ -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 diff --git a/signer/fourbyte/fourbyte.go b/signer/fourbyte/fourbyte.go index 67b46afb0157..090344523eac 100644 --- a/signer/fourbyte/fourbyte.go +++ b/signer/fourbyte/fourbyte.go @@ -14,14 +14,11 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -nocompress -o 4byte.go -pkg fourbyte 4byte.json -//go:generate gofmt -s -w 4byte.go -//go:generate sh -c "sed 's#var __4byteJson#//nolint:misspell\\\n&#' 4byte.go > 4byte.go.tmp && mv 4byte.go.tmp 4byte.go" - // Package fourbyte contains the 4byte database. package fourbyte import ( + _ "embed" "encoding/hex" "encoding/json" "fmt" @@ -29,6 +26,9 @@ import ( "os" ) +//go:embed 4byte.json +var embeddedJSON []byte + // Database is a 4byte database with the possibility of maintaining an immutable // set (embedded) into the process and a mutable set (loaded and written to file). type Database struct { @@ -77,15 +77,12 @@ func NewWithFile(path string) (*Database, error) { db := &Database{make(map[string]string), make(map[string]string), path} db.customPath = path - blob, err := Asset("4byte.json") - if err != nil { - return nil, err - } - if err := json.Unmarshal(blob, &db.embedded); err != nil { + if err := json.Unmarshal(embeddedJSON, &db.embedded); err != nil { return nil, err } // Custom file may not exist. Will be created during save, if needed. if _, err := os.Stat(path); err == nil { + var blob []byte if blob, err = ioutil.ReadFile(path); err != nil { return nil, err } diff --git a/signer/rules/rules.go b/signer/rules/rules.go index f37209f64541..6852d86f3ec7 100644 --- a/signer/rules/rules.go +++ b/signer/rules/rules.go @@ -30,10 +30,6 @@ import ( "github.com/ethereum/go-ethereum/signer/storage" ) -var ( - BigNumber_JS = deps.MustAsset("bignumber.js") -) - // consoleOutput is an override for the console.log and console.error methods to // stream the output into the configured output stream instead of stdout. func consoleOutput(call goja.FunctionCall) goja.Value { @@ -99,7 +95,7 @@ func (r *rulesetUI) execute(jsfunc string, jsarg interface{}) (goja.Value, error vm.Set("storage", storageObj) // Load bootstrap libraries - script, err := goja.Compile("bignumber.js", string(BigNumber_JS), true) + script, err := goja.Compile("bignumber.js", deps.BigNumberJS, true) if err != nil { log.Warn("Failed loading libraries", "err", err) return goja.Undefined(), err