tracers.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // Package tracers is a collection of JavaScript transaction tracers.
  17. package tracers
  18. import (
  19. "strings"
  20. "unicode"
  21. "github.com/ethereum/go-ethereum/eth/tracers/internal/tracers"
  22. )
  23. // all contains all the built in JavaScript tracers by name.
  24. var all = make(map[string]string)
  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. // init retrieves the JavaScript transaction tracers included in go-ethereum.
  34. func init() {
  35. for _, file := range tracers.AssetNames() {
  36. name := camel(strings.TrimSuffix(file, ".js"))
  37. all[name] = string(tracers.MustAsset(file))
  38. }
  39. }
  40. // tracer retrieves a specific JavaScript tracer by name.
  41. func tracer(name string) (string, bool) {
  42. if tracer, ok := all[name]; ok {
  43. return tracer, true
  44. }
  45. return "", false
  46. }