github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/state/runtime/instrumentation/js/internal/tracers/tracers.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package tracers contains the actual JavaScript tracer assets. 18 package tracers 19 20 import ( 21 "embed" 22 "io/fs" 23 "strings" 24 "unicode" 25 ) 26 27 //go:embed *.js 28 var files embed.FS 29 30 // Load reads the built-in JS tracer files embedded in the binary and 31 // returns a mapping of tracer name to source. 32 func Load() (map[string]string, error) { 33 var assetTracers = make(map[string]string) 34 err := fs.WalkDir(files, ".", func(path string, d fs.DirEntry, err error) error { 35 if err != nil { 36 return err 37 } 38 if d.IsDir() { 39 return nil 40 } 41 b, err := fs.ReadFile(files, path) 42 if err != nil { 43 return err 44 } 45 name := camel(strings.TrimSuffix(path, ".js")) 46 assetTracers[name] = string(b) 47 return nil 48 }) 49 return assetTracers, err 50 } 51 52 // camel converts a snake cased input string into a camel cased output. 53 func camel(str string) string { 54 pieces := strings.Split(str, "_") 55 for i := 1; i < len(pieces); i++ { 56 pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:] 57 } 58 return strings.Join(pieces, "") 59 }