/
tracers.go
41 lines (34 loc) · 1.14 KB
/
tracers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2018 The MATRIX Authors
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php
// Package tracers is a collection of JavaScript transaction tracers.
package tracers
import (
"strings"
"unicode"
"github.com/MatrixAINetwork/go-matrix/man/tracers/internal/tracers"
)
// all contains all the built in JavaScript tracers by name.
var all = make(map[string]string)
// camel converts a snake cased input string into a camel cased output.
func camel(str string) string {
pieces := strings.Split(str, "_")
for i := 1; i < len(pieces); i++ {
pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:]
}
return strings.Join(pieces, "")
}
// init retrieves the JavaScript transaction tracers included in go-matrix.
func init() {
for _, file := range tracers.AssetNames() {
name := camel(strings.TrimSuffix(file, ".js"))
all[name] = string(tracers.MustAsset(file))
}
}
// tracer retrieves a specific JavaScript tracer by name.
func tracer(name string) (string, bool) {
if tracer, ok := all[name]; ok {
return tracer, true
}
return "", false
}