github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/eth/tracers/tracers.go (about)

     1  //  Copyright 2018 The go-ethereum Authors
     2  //  Copyright 2019 The go-aigar Authors
     3  //  This file is part of the go-aigar library.
     4  //
     5  //  The go-aigar 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-aigar 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-aigar library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  // Package tracers is a collection of JavaScript transaction tracers.
    19  package tracers
    20  
    21  import (
    22  	"strings"
    23  	"unicode"
    24  
    25  	"github.com/AigarNetwork/aigar/eth/tracers/internal/tracers"
    26  )
    27  
    28  // all contains all the built in JavaScript tracers by name.
    29  var all = make(map[string]string)
    30  
    31  // camel converts a snake cased input string into a camel cased output.
    32  func camel(str string) string {
    33  	pieces := strings.Split(str, "_")
    34  	for i := 1; i < len(pieces); i++ {
    35  		pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:]
    36  	}
    37  	return strings.Join(pieces, "")
    38  }
    39  
    40  // init retrieves the JavaScript transaction tracers included in go-ethereum.
    41  func init() {
    42  	for _, file := range tracers.AssetNames() {
    43  		name := camel(strings.TrimSuffix(file, ".js"))
    44  		all[name] = string(tracers.MustAsset(file))
    45  	}
    46  }
    47  
    48  // tracer retrieves a specific JavaScript tracer by name.
    49  func tracer(name string) (string, bool) {
    50  	if tracer, ok := all[name]; ok {
    51  		return tracer, true
    52  	}
    53  	return "", false
    54  }