mirror of https://github.com/ethereum/go-ethereum
eth/tracers: use gencodec for native tracers (#25637)
The call tracer and prestate tracer store data JSON-encoded in memory. In order to support alternative encodings (specifically RLP), it's better to keep data a native format during tracing. This PR does marshalling at the end, using gencodec. OBS! This PR changes the call tracer result slightly: - Order of type and value fields are changed (should not matter). - Output fields are completely omitted when they're empty (no more output: "0x"). Previously, this was only _sometimes_ omitted (e.g. when call ended in a non-revert error) and otherwise 0x when the output was actually empty.pull/25876/head
parent
3ec6fe6101
commit
fc3e6d0162
@ -0,0 +1,56 @@ |
||||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||
|
||||
package native |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/hexutil" |
||||
) |
||||
|
||||
var _ = (*accountMarshaling)(nil) |
||||
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (a account) MarshalJSON() ([]byte, error) { |
||||
type account struct { |
||||
Balance *hexutil.Big `json:"balance"` |
||||
Nonce uint64 `json:"nonce"` |
||||
Code hexutil.Bytes `json:"code"` |
||||
Storage map[common.Hash]common.Hash `json:"storage"` |
||||
} |
||||
var enc account |
||||
enc.Balance = (*hexutil.Big)(a.Balance) |
||||
enc.Nonce = a.Nonce |
||||
enc.Code = a.Code |
||||
enc.Storage = a.Storage |
||||
return json.Marshal(&enc) |
||||
} |
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (a *account) UnmarshalJSON(input []byte) error { |
||||
type account struct { |
||||
Balance *hexutil.Big `json:"balance"` |
||||
Nonce *uint64 `json:"nonce"` |
||||
Code *hexutil.Bytes `json:"code"` |
||||
Storage map[common.Hash]common.Hash `json:"storage"` |
||||
} |
||||
var dec account |
||||
if err := json.Unmarshal(input, &dec); err != nil { |
||||
return err |
||||
} |
||||
if dec.Balance != nil { |
||||
a.Balance = (*big.Int)(dec.Balance) |
||||
} |
||||
if dec.Nonce != nil { |
||||
a.Nonce = *dec.Nonce |
||||
} |
||||
if dec.Code != nil { |
||||
a.Code = *dec.Code |
||||
} |
||||
if dec.Storage != nil { |
||||
a.Storage = dec.Storage |
||||
} |
||||
return nil |
||||
} |
@ -0,0 +1,95 @@ |
||||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||
|
||||
package native |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/hexutil" |
||||
"github.com/ethereum/go-ethereum/core/vm" |
||||
) |
||||
|
||||
var _ = (*callFrameMarshaling)(nil) |
||||
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (c callFrame) MarshalJSON() ([]byte, error) { |
||||
type callFrame0 struct { |
||||
Type vm.OpCode `json:"-"` |
||||
From common.Address `json:"from"` |
||||
To common.Address `json:"to,omitempty" rlp:"optional"` |
||||
Gas hexutil.Uint64 `json:"gas"` |
||||
GasUsed hexutil.Uint64 `json:"gasUsed"` |
||||
Input hexutil.Bytes `json:"input" rlp:"optional"` |
||||
Output hexutil.Bytes `json:"output,omitempty" rlp:"optional"` |
||||
Error string `json:"error,omitempty" rlp:"optional"` |
||||
Calls []callFrame `json:"calls,omitempty" rlp:"optional"` |
||||
Value *hexutil.Big `json:"value,omitempty" rlp:"optional"` |
||||
TypeString string `json:"type"` |
||||
} |
||||
var enc callFrame0 |
||||
enc.Type = c.Type |
||||
enc.From = c.From |
||||
enc.To = c.To |
||||
enc.Gas = hexutil.Uint64(c.Gas) |
||||
enc.GasUsed = hexutil.Uint64(c.GasUsed) |
||||
enc.Input = c.Input |
||||
enc.Output = c.Output |
||||
enc.Error = c.Error |
||||
enc.Calls = c.Calls |
||||
enc.Value = (*hexutil.Big)(c.Value) |
||||
enc.TypeString = c.TypeString() |
||||
return json.Marshal(&enc) |
||||
} |
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (c *callFrame) UnmarshalJSON(input []byte) error { |
||||
type callFrame0 struct { |
||||
Type *vm.OpCode `json:"-"` |
||||
From *common.Address `json:"from"` |
||||
To *common.Address `json:"to,omitempty" rlp:"optional"` |
||||
Gas *hexutil.Uint64 `json:"gas"` |
||||
GasUsed *hexutil.Uint64 `json:"gasUsed"` |
||||
Input *hexutil.Bytes `json:"input" rlp:"optional"` |
||||
Output *hexutil.Bytes `json:"output,omitempty" rlp:"optional"` |
||||
Error *string `json:"error,omitempty" rlp:"optional"` |
||||
Calls []callFrame `json:"calls,omitempty" rlp:"optional"` |
||||
Value *hexutil.Big `json:"value,omitempty" rlp:"optional"` |
||||
} |
||||
var dec callFrame0 |
||||
if err := json.Unmarshal(input, &dec); err != nil { |
||||
return err |
||||
} |
||||
if dec.Type != nil { |
||||
c.Type = *dec.Type |
||||
} |
||||
if dec.From != nil { |
||||
c.From = *dec.From |
||||
} |
||||
if dec.To != nil { |
||||
c.To = *dec.To |
||||
} |
||||
if dec.Gas != nil { |
||||
c.Gas = uint64(*dec.Gas) |
||||
} |
||||
if dec.GasUsed != nil { |
||||
c.GasUsed = uint64(*dec.GasUsed) |
||||
} |
||||
if dec.Input != nil { |
||||
c.Input = *dec.Input |
||||
} |
||||
if dec.Output != nil { |
||||
c.Output = *dec.Output |
||||
} |
||||
if dec.Error != nil { |
||||
c.Error = *dec.Error |
||||
} |
||||
if dec.Calls != nil { |
||||
c.Calls = dec.Calls |
||||
} |
||||
if dec.Value != nil { |
||||
c.Value = (*big.Int)(dec.Value) |
||||
} |
||||
return nil |
||||
} |
Loading…
Reference in new issue