github.com/coltonfike/e2c@v21.1.0+incompatible/eth/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 is a collection of JavaScript transaction tracers.
    18  package tracers
    19  
    20  import (
    21  	"strings"
    22  	"unicode"
    23  
    24  	"github.com/ethereum/go-ethereum/eth/tracers/internal/tracers"
    25  )
    26  
    27  // all contains all the built in JavaScript tracers by name.
    28  var all = make(map[string]string)
    29  
    30  // camel converts a snake cased input string into a camel cased output.
    31  func camel(str string) string {
    32  	pieces := strings.Split(str, "_")
    33  	for i := 1; i < len(pieces); i++ {
    34  		pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:]
    35  	}
    36  	return strings.Join(pieces, "")
    37  }
    38  
    39  // init retrieves the JavaScript transaction tracers included in go-ethereum.
    40  func init() {
    41  	for _, file := range tracers.AssetNames() {
    42  		name := camel(strings.TrimSuffix(file, ".js"))
    43  		all[name] = string(tracers.MustAsset(file))
    44  	}
    45  }
    46  
    47  // tracer retrieves a specific JavaScript tracer by name.
    48  func tracer(name string) (string, bool) {
    49  	if tracer, ok := all[name]; ok {
    50  		return tracer, true
    51  	}
    52  	return "", false
    53  }