fix generated account marshaler

This commit is contained in:
Sina Mahmoodi 2025-08-12 13:05:47 +02:00
parent 83d1318bbe
commit 40968d8b13

View file

@ -8,7 +8,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
) )
var _ = (*accountMarshaling)(nil) var _ = (*accountMarshaling)(nil)
@ -18,16 +17,14 @@ func (a account) MarshalJSON() ([]byte, error) {
type account struct { type account struct {
Balance *hexutil.Big `json:"balance,omitempty"` Balance *hexutil.Big `json:"balance,omitempty"`
Code hexutil.Bytes `json:"code,omitempty"` Code hexutil.Bytes `json:"code,omitempty"`
CodeHash *common.Hash `json:"codeHash,omitempty"` CodeHash common.Hash `json:"codeHash,omitempty"`
Nonce uint64 `json:"nonce,omitempty"` Nonce uint64 `json:"nonce,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
} }
var enc account var enc account
enc.Balance = (*hexutil.Big)(a.Balance) enc.Balance = (*hexutil.Big)(a.Balance)
enc.Code = a.Code enc.Code = a.Code
if a.CodeHash != (common.Hash{}) && a.CodeHash != types.EmptyCodeHash { enc.CodeHash = a.CodeHash
enc.CodeHash = &a.CodeHash
}
enc.Nonce = a.Nonce enc.Nonce = a.Nonce
enc.Storage = a.Storage enc.Storage = a.Storage
return json.Marshal(&enc) return json.Marshal(&enc)
@ -52,7 +49,7 @@ func (a *account) UnmarshalJSON(input []byte) error {
if dec.Code != nil { if dec.Code != nil {
a.Code = *dec.Code a.Code = *dec.Code
} }
if dec.CodeHash != nil && *dec.CodeHash != (common.Hash{}) && *dec.CodeHash != types.EmptyCodeHash { if dec.CodeHash != nil {
a.CodeHash = *dec.CodeHash a.CodeHash = *dec.CodeHash
} }
if dec.Nonce != nil { if dec.Nonce != nil {