github.com/klaytn/klaytn@v1.12.1/node/cn/tracers/tracers.go (about)

     1  // Copyright 2018 The klaytn Authors
     2  // Copyright 2017 The go-ethereum Authors
     3  // This file is part of the go-ethereum library.
     4  //
     5  // The go-ethereum library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The go-ethereum library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  // This file is derived from eth/tracers/tracers.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  // Package tracers is a collection of JavaScript transaction tracers.
    22  package tracers
    23  
    24  import (
    25  	"strings"
    26  	"unicode"
    27  
    28  	"github.com/klaytn/klaytn/node/cn/tracers/internal/tracers"
    29  )
    30  
    31  // all contains all the built in JavaScript tracers by name.
    32  var all = make(map[string]string)
    33  
    34  // camel converts a snake cased input string into a camel cased output.
    35  func camel(str string) string {
    36  	pieces := strings.Split(str, "_")
    37  	for i := 1; i < len(pieces); i++ {
    38  		pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:]
    39  	}
    40  	return strings.Join(pieces, "")
    41  }
    42  
    43  // init retrieves the JavaScript transaction tracers included in Klaytn.
    44  func init() {
    45  	for _, file := range tracers.AssetNames() {
    46  		name := camel(strings.TrimSuffix(file, ".js"))
    47  		all[name] = string(tracers.MustAsset(file))
    48  	}
    49  }
    50  
    51  // tracer retrieves a specific JavaScript tracer by name.
    52  func tracer(name string) (string, bool) {
    53  	if tracer, ok := all[name]; ok {
    54  		return tracer, true
    55  	}
    56  	return "", false
    57  }