2015-07-06 17:54:22 -07:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-07-22 09:48:40 -07:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-06 17:54:22 -07:00
|
|
|
//
|
2015-07-23 09:35:11 -07:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-06 17:54:22 -07:00
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2015-07-22 09:48:40 -07:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-06 17:54:22 -07:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 09:48:40 -07:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-06 17:54:22 -07:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 09:48:40 -07:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-06 17:54:22 -07:00
|
|
|
|
2017-01-05 05:03:50 -08:00
|
|
|
package types
|
2014-10-27 03:44:16 -07:00
|
|
|
|
2014-11-11 03:16:36 -08:00
|
|
|
import (
|
|
|
|
"fmt"
|
2015-03-16 15:10:26 -07:00
|
|
|
"io"
|
2014-11-11 03:16:36 -08:00
|
|
|
|
2015-03-16 03:27:38 -07:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2016-11-27 15:25:48 -08:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2015-03-16 15:10:26 -07:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2014-11-11 03:16:36 -08:00
|
|
|
)
|
2014-10-27 03:44:16 -07:00
|
|
|
|
2017-02-23 08:58:15 -08:00
|
|
|
//go:generate gencodec -type Log -field-override logMarshaling -out gen_log_json.go
|
2016-08-03 18:55:33 -07:00
|
|
|
|
2016-12-04 10:07:24 -08:00
|
|
|
// Log represents a contract log event. These events are generated by the LOG opcode and
|
|
|
|
// stored/indexed by the node.
|
2015-04-08 08:14:58 -07:00
|
|
|
type Log struct {
|
2017-02-23 08:58:15 -08:00
|
|
|
// Consensus fields:
|
|
|
|
// address of the contract that generated the event
|
2017-04-06 01:38:21 -07:00
|
|
|
Address common.Address `json:"address" gencodec:"required"`
|
2017-02-23 08:58:15 -08:00
|
|
|
// list of topics provided by the contract.
|
2017-04-06 01:38:21 -07:00
|
|
|
Topics []common.Hash `json:"topics" gencodec:"required"`
|
2017-02-23 08:58:15 -08:00
|
|
|
// supplied by the contract, usually ABI-encoded
|
2017-04-06 01:38:21 -07:00
|
|
|
Data []byte `json:"data" gencodec:"required"`
|
2016-08-03 18:55:33 -07:00
|
|
|
|
2016-12-04 10:07:24 -08:00
|
|
|
// Derived fields. These fields are filled in by the node
|
|
|
|
// but not secured by consensus.
|
2017-02-23 08:58:15 -08:00
|
|
|
// block in which the transaction was included
|
2017-04-06 01:38:21 -07:00
|
|
|
BlockNumber uint64 `json:"blockNumber"`
|
2017-02-23 08:58:15 -08:00
|
|
|
// hash of the transaction
|
2017-04-06 01:38:21 -07:00
|
|
|
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
2017-02-23 08:58:15 -08:00
|
|
|
// index of the transaction in the block
|
2017-04-06 01:38:21 -07:00
|
|
|
TxIndex uint `json:"transactionIndex" gencodec:"required"`
|
2017-02-23 08:58:15 -08:00
|
|
|
// hash of the block in which the transaction was included
|
2017-04-06 01:38:21 -07:00
|
|
|
BlockHash common.Hash `json:"blockHash"`
|
2017-02-23 08:58:15 -08:00
|
|
|
// index of the log in the receipt
|
2017-04-06 01:38:21 -07:00
|
|
|
Index uint `json:"logIndex" gencodec:"required"`
|
2016-12-04 10:07:24 -08:00
|
|
|
|
|
|
|
// The Removed field is true if this log was reverted due to a chain reorganisation.
|
|
|
|
// You must pay attention to this field if you receive logs through a filter query.
|
2017-04-06 01:38:21 -07:00
|
|
|
Removed bool `json:"removed"`
|
2017-02-23 08:58:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type logMarshaling struct {
|
|
|
|
Data hexutil.Bytes
|
|
|
|
BlockNumber hexutil.Uint64
|
|
|
|
TxIndex hexutil.Uint
|
|
|
|
Index hexutil.Uint
|
2016-12-04 10:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type rlpLog struct {
|
|
|
|
Address common.Address
|
|
|
|
Topics []common.Hash
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type rlpStorageLog struct {
|
|
|
|
Address common.Address
|
|
|
|
Topics []common.Hash
|
|
|
|
Data []byte
|
|
|
|
BlockNumber uint64
|
|
|
|
TxHash common.Hash
|
|
|
|
TxIndex uint
|
|
|
|
BlockHash common.Hash
|
|
|
|
Index uint
|
2016-08-03 18:55:33 -07:00
|
|
|
}
|
2015-02-22 04:24:26 -08:00
|
|
|
|
2016-12-04 10:07:24 -08:00
|
|
|
// EncodeRLP implements rlp.Encoder.
|
2015-09-29 09:36:16 -07:00
|
|
|
func (l *Log) EncodeRLP(w io.Writer) error {
|
2016-12-04 10:07:24 -08:00
|
|
|
return rlp.Encode(w, rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data})
|
2014-12-04 03:35:23 -08:00
|
|
|
}
|
|
|
|
|
2016-12-04 10:07:24 -08:00
|
|
|
// DecodeRLP implements rlp.Decoder.
|
2015-09-29 09:36:16 -07:00
|
|
|
func (l *Log) DecodeRLP(s *rlp.Stream) error {
|
2016-12-04 10:07:24 -08:00
|
|
|
var dec rlpLog
|
|
|
|
err := s.Decode(&dec)
|
|
|
|
if err == nil {
|
|
|
|
l.Address, l.Topics, l.Data = dec.Address, dec.Topics, dec.Data
|
2015-09-29 09:36:16 -07:00
|
|
|
}
|
2016-12-04 10:07:24 -08:00
|
|
|
return err
|
2015-09-29 09:36:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Log) String() string {
|
|
|
|
return fmt.Sprintf(`log: %x %x %x %x %d %x %d`, l.Address, l.Topics, l.Data, l.TxHash, l.TxIndex, l.BlockHash, l.Index)
|
2014-12-04 03:35:23 -08:00
|
|
|
}
|
|
|
|
|
2016-12-04 10:07:24 -08:00
|
|
|
// LogForStorage is a wrapper around a Log that flattens and parses the entire content of
|
|
|
|
// a log including non-consensus fields.
|
2015-05-22 13:44:51 -07:00
|
|
|
type LogForStorage Log
|
2016-12-04 10:07:24 -08:00
|
|
|
|
|
|
|
// EncodeRLP implements rlp.Encoder.
|
|
|
|
func (l *LogForStorage) EncodeRLP(w io.Writer) error {
|
|
|
|
return rlp.Encode(w, rlpStorageLog{
|
|
|
|
Address: l.Address,
|
|
|
|
Topics: l.Topics,
|
|
|
|
Data: l.Data,
|
|
|
|
BlockNumber: l.BlockNumber,
|
|
|
|
TxHash: l.TxHash,
|
|
|
|
TxIndex: l.TxIndex,
|
|
|
|
BlockHash: l.BlockHash,
|
|
|
|
Index: l.Index,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeRLP implements rlp.Decoder.
|
|
|
|
func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error {
|
|
|
|
var dec rlpStorageLog
|
|
|
|
err := s.Decode(&dec)
|
|
|
|
if err == nil {
|
|
|
|
*l = LogForStorage{
|
|
|
|
Address: dec.Address,
|
|
|
|
Topics: dec.Topics,
|
|
|
|
Data: dec.Data,
|
|
|
|
BlockNumber: dec.BlockNumber,
|
|
|
|
TxHash: dec.TxHash,
|
|
|
|
TxIndex: dec.TxIndex,
|
|
|
|
BlockHash: dec.BlockHash,
|
|
|
|
Index: dec.Index,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|