bsc/eth/tracers/native/gen_account_json.go
Sina Mahmoodi fc3e6d0162
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.
2022-09-26 18:35:44 +02:00

57 lines
1.3 KiB
Go

// 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
}