2020-04-08 22:27:31 +00:00
|
|
|
package types
|
|
|
|
|
2020-06-11 19:59:39 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
2020-06-02 19:53:24 +00:00
|
|
|
|
2020-06-11 00:47:28 +00:00
|
|
|
type ExecutionTrace struct {
|
2020-06-11 19:59:39 +00:00
|
|
|
Msg *Message
|
|
|
|
MsgRct *MessageReceipt
|
|
|
|
Error string
|
|
|
|
Duration time.Duration
|
|
|
|
GasCharges []*GasTrace
|
2020-04-08 22:27:31 +00:00
|
|
|
|
2020-06-11 00:47:28 +00:00
|
|
|
Subcalls []ExecutionTrace
|
2020-04-08 22:27:31 +00:00
|
|
|
}
|
2020-06-11 19:59:39 +00:00
|
|
|
|
|
|
|
type GasTrace struct {
|
|
|
|
Name string
|
|
|
|
Location string
|
|
|
|
TotalGas int64
|
|
|
|
ComputeGas int64
|
|
|
|
StorageGas int64
|
|
|
|
|
|
|
|
TimeTaken time.Duration
|
|
|
|
|
|
|
|
Callers []uintptr `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gt *GasTrace) MarshalJSON() ([]byte, error) {
|
|
|
|
type GasTraceCopy GasTrace
|
|
|
|
if gt.Location == "" {
|
|
|
|
if len(gt.Callers) != 0 {
|
|
|
|
frames := runtime.CallersFrames(gt.Callers)
|
|
|
|
for {
|
|
|
|
frame, more := frames.Next()
|
|
|
|
fn := strings.Split(frame.Function, "/")
|
|
|
|
|
|
|
|
split := strings.Split(frame.File, "/")
|
|
|
|
file := strings.Join(split[len(split)-2:], "/")
|
|
|
|
gt.Location += fmt.Sprintf("%s@%s:%d", fn[len(fn)-1], file, frame.Line)
|
|
|
|
if !more {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
gt.Location += "|"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gt.Location = "n/a"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cpy := (*GasTraceCopy)(gt)
|
|
|
|
return json.Marshal(cpy)
|
|
|
|
}
|