diff options
Diffstat (limited to 'core/vm/log.go')
-rw-r--r-- | core/vm/log.go | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/core/vm/log.go b/core/vm/log.go index b292f5f43..06f941703 100644 --- a/core/vm/log.go +++ b/core/vm/log.go @@ -23,6 +23,7 @@ import ( "io" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/rlp" ) @@ -47,12 +48,12 @@ type Log struct { type jsonLog struct { Address *common.Address `json:"address"` Topics *[]common.Hash `json:"topics"` - Data string `json:"data"` - BlockNumber string `json:"blockNumber"` - TxIndex string `json:"transactionIndex"` + Data *hexutil.Bytes `json:"data"` + BlockNumber *hexutil.Uint64 `json:"blockNumber"` + TxIndex *hexutil.Uint `json:"transactionIndex"` TxHash *common.Hash `json:"transactionHash"` BlockHash *common.Hash `json:"blockHash"` - Index string `json:"logIndex"` + Index *hexutil.Uint `json:"logIndex"` } func NewLog(address common.Address, topics []common.Hash, data []byte, number uint64) *Log { @@ -85,12 +86,12 @@ func (r *Log) MarshalJSON() ([]byte, error) { return json.Marshal(&jsonLog{ Address: &r.Address, Topics: &r.Topics, - Data: fmt.Sprintf("0x%x", r.Data), - BlockNumber: fmt.Sprintf("0x%x", r.BlockNumber), - TxIndex: fmt.Sprintf("0x%x", r.TxIndex), + Data: (*hexutil.Bytes)(&r.Data), + BlockNumber: (*hexutil.Uint64)(&r.BlockNumber), + TxIndex: (*hexutil.Uint)(&r.TxIndex), TxHash: &r.TxHash, BlockHash: &r.BlockHash, - Index: fmt.Sprintf("0x%x", r.Index), + Index: (*hexutil.Uint)(&r.Index), }) } @@ -100,29 +101,20 @@ func (r *Log) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &dec); err != nil { return err } - if dec.Address == nil || dec.Topics == nil || dec.Data == "" || dec.BlockNumber == "" || - dec.TxIndex == "" || dec.TxHash == nil || dec.BlockHash == nil || dec.Index == "" { + if dec.Address == nil || dec.Topics == nil || dec.Data == nil || dec.BlockNumber == nil || + dec.TxIndex == nil || dec.TxHash == nil || dec.BlockHash == nil || dec.Index == nil { return errMissingLogFields } - declog := Log{ - Address: *dec.Address, - Topics: *dec.Topics, - TxHash: *dec.TxHash, - BlockHash: *dec.BlockHash, + *r = Log{ + Address: *dec.Address, + Topics: *dec.Topics, + Data: *dec.Data, + BlockNumber: uint64(*dec.BlockNumber), + TxHash: *dec.TxHash, + TxIndex: uint(*dec.TxIndex), + BlockHash: *dec.BlockHash, + Index: uint(*dec.Index), } - if _, err := fmt.Sscanf(dec.Data, "0x%x", &declog.Data); err != nil { - return fmt.Errorf("invalid hex log data") - } - if _, err := fmt.Sscanf(dec.BlockNumber, "0x%x", &declog.BlockNumber); err != nil { - return fmt.Errorf("invalid hex log block number") - } - if _, err := fmt.Sscanf(dec.TxIndex, "0x%x", &declog.TxIndex); err != nil { - return fmt.Errorf("invalid hex log tx index") - } - if _, err := fmt.Sscanf(dec.Index, "0x%x", &declog.Index); err != nil { - return fmt.Errorf("invalid hex log index") - } - *r = declog return nil } |