plugeth/eth/tracers/native/gen_flatcallresult_json.go
Chris Ziogas 2ad150d986
eth/tracers: add native flatCallTracer (aka parity style tracer) (#26377)
Adds support for a native call tracer with the Parity format, which outputs call frames
in a flat array. This tracer accepts the following options:

- `convertParityErrors: true` will convert error messages to match those of Parity
- `includePrecompiles: true` will report all calls to precompiles. The default
  matches Parity's behavior where CALL and STATICCALLs to precompiles are excluded

Incompatibilities with Parity include:

- Parity removes the result object in case of failure. This behavior is maintained
  with the exception of reverts. Revert output usually contains useful information,
  i.e. Solidity revert reason.
- The `gasUsed` field accounts for intrinsic gas (e.g. 21000 for simple transfers)
  and refunds unlike Parity
- Block rewards are not reported

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2023-02-28 13:54:37 +03:30

56 lines
1.4 KiB
Go

// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package native
import (
"encoding/json"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
var _ = (*flatCallResultMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (f flatCallResult) MarshalJSON() ([]byte, error) {
type flatCallResult struct {
Address *common.Address `json:"address,omitempty"`
Code *hexutil.Bytes `json:"code,omitempty"`
GasUsed *hexutil.Uint64 `json:"gasUsed,omitempty"`
Output *hexutil.Bytes `json:"output,omitempty"`
}
var enc flatCallResult
enc.Address = f.Address
enc.Code = (*hexutil.Bytes)(f.Code)
enc.GasUsed = (*hexutil.Uint64)(f.GasUsed)
enc.Output = (*hexutil.Bytes)(f.Output)
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (f *flatCallResult) UnmarshalJSON(input []byte) error {
type flatCallResult struct {
Address *common.Address `json:"address,omitempty"`
Code *hexutil.Bytes `json:"code,omitempty"`
GasUsed *hexutil.Uint64 `json:"gasUsed,omitempty"`
Output *hexutil.Bytes `json:"output,omitempty"`
}
var dec flatCallResult
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.Address != nil {
f.Address = dec.Address
}
if dec.Code != nil {
f.Code = (*[]byte)(dec.Code)
}
if dec.GasUsed != nil {
f.GasUsed = (*uint64)(dec.GasUsed)
}
if dec.Output != nil {
f.Output = (*[]byte)(dec.Output)
}
return nil
}