all: use 'embed' instead of go-bindata (#24744)

pull/24760/head
s7v7nislands 3 years ago committed by GitHub
parent 63972e7548
commit 7ab15490e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Makefile
  2. 1
      build/tools/tools.go
  3. 14
      cmd/faucet/faucet.go
  4. 274
      cmd/faucet/website.go
  5. 6
      console/console.go
  6. 458
      eth/tracers/js/internal/tracers/assets.go
  7. 8
      eth/tracers/js/internal/tracers/tracers.go
  8. 25
      eth/tracers/js/tracer.go
  9. 3
      go.mod
  10. 2
      go.sum
  11. 297
      internal/jsre/deps/bindata.go
  12. 11
      internal/jsre/deps/deps.go
  13. 147091
      signer/fourbyte/4byte.go
  14. 15
      signer/fourbyte/fourbyte.go
  15. 6
      signer/rules/rules.go

@ -43,7 +43,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

@ -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.

@ -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,

File diff suppressed because one or more lines are too long

@ -179,12 +179,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 {

File diff suppressed because one or more lines are too long

@ -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

@ -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 <http://www.gnu.org/licenses/>.
// 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) {}

@ -1,6 +1,6 @@
module github.com/ethereum/go-ethereum
go 1.15
go 1.16
require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0
@ -46,7 +46,6 @@ require (
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
github.com/julienschmidt/httprouter v1.2.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

@ -256,8 +256,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.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=

File diff suppressed because one or more lines are too long

@ -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

File diff suppressed because it is too large Load Diff

@ -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 <http://www.gnu.org/licenses/>.
//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
}

@ -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

Loading…
Cancel
Save