github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/eth/tracers/tracers.go (about)

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