2020-04-08 22:27:31 +00:00
|
|
|
package types
|
|
|
|
|
2020-06-11 19:59:39 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"time"
|
2020-04-08 22:27:31 +00:00
|
|
|
|
2023-03-02 00:02:18 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/exitcode"
|
|
|
|
)
|
2020-06-11 19:59:39 +00:00
|
|
|
|
|
|
|
type GasTrace struct {
|
2023-03-02 00:02:18 +00:00
|
|
|
Name string
|
|
|
|
TotalGas int64 `json:"tg"`
|
|
|
|
ComputeGas int64 `json:"cg"`
|
|
|
|
StorageGas int64 `json:"sg"`
|
|
|
|
TimeTaken time.Duration `json:"tt"`
|
|
|
|
}
|
2020-06-25 14:46:50 +00:00
|
|
|
|
2023-03-02 00:02:18 +00:00
|
|
|
type MessageTrace struct {
|
|
|
|
From address.Address
|
|
|
|
To address.Address
|
|
|
|
Value abi.TokenAmount
|
|
|
|
Method abi.MethodNum
|
|
|
|
Params []byte
|
|
|
|
ParamsCodec uint64
|
|
|
|
}
|
2020-06-11 19:59:39 +00:00
|
|
|
|
2023-03-02 00:02:18 +00:00
|
|
|
type ReturnTrace struct {
|
|
|
|
ExitCode exitcode.ExitCode
|
|
|
|
Return []byte
|
|
|
|
ReturnCodec uint64
|
2020-06-11 19:59:39 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 00:02:18 +00:00
|
|
|
type ExecutionTrace struct {
|
|
|
|
Msg MessageTrace
|
|
|
|
MsgRct ReturnTrace
|
|
|
|
GasCharges []*GasTrace `cborgen:"maxlen=1000000000"`
|
|
|
|
Subcalls []ExecutionTrace `cborgen:"maxlen=1000000000"`
|
2020-06-12 16:49:29 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 20:07:23 +00:00
|
|
|
func (et ExecutionTrace) SumGas() GasTrace {
|
|
|
|
return SumGas(et.GasCharges)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SumGas(charges []*GasTrace) GasTrace {
|
|
|
|
var out GasTrace
|
|
|
|
for _, gc := range charges {
|
|
|
|
out.TotalGas += gc.TotalGas
|
|
|
|
out.ComputeGas += gc.ComputeGas
|
|
|
|
out.StorageGas += gc.StorageGas
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-06-11 19:59:39 +00:00
|
|
|
func (gt *GasTrace) MarshalJSON() ([]byte, error) {
|
|
|
|
type GasTraceCopy GasTrace
|
|
|
|
cpy := (*GasTraceCopy)(gt)
|
|
|
|
return json.Marshal(cpy)
|
|
|
|
}
|