mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/types: implement log.EncodeRLP
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
7c06c7bc4b
commit
fe8bf2df9e
1 changed files with 20 additions and 3 deletions
|
|
@ -17,13 +17,13 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"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/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run ../../rlp/rlpgen -type Log -out gen_log_rlp.go
|
|
||||||
//go:generate go run github.com/fjl/gencodec -type Log -field-override logMarshaling -out gen_log_json.go
|
|
||||||
|
|
||||||
// Log represents a contract log event. These events are generated by the LOG opcode and
|
// Log represents a contract log event. These events are generated by the LOG opcode and
|
||||||
// stored/indexed by the node.
|
// stored/indexed by the node.
|
||||||
type Log struct {
|
type Log struct {
|
||||||
|
|
@ -53,6 +53,23 @@ type Log struct {
|
||||||
Removed bool `json:"removed" rlp:"-"`
|
Removed bool `json:"removed" rlp:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a log
|
||||||
|
// into an RLP stream.
|
||||||
|
func (log *Log) EncodeRLP(_w io.Writer) error {
|
||||||
|
w := rlp.NewEncoderBuffer(_w)
|
||||||
|
outerList := w.List()
|
||||||
|
w.WriteBytes(log.Address[:])
|
||||||
|
topicList := w.List()
|
||||||
|
for _, topic := range log.Topics {
|
||||||
|
w.WriteBytes(topic[:])
|
||||||
|
}
|
||||||
|
w.ListEnd(topicList)
|
||||||
|
w.WriteBytes(log.Data)
|
||||||
|
w.ListEnd(outerList)
|
||||||
|
return w.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:generate go run github.com/fjl/gencodec -type Log -field-override logMarshaling -out gen_log_json.go
|
||||||
type logMarshaling struct {
|
type logMarshaling struct {
|
||||||
Data hexutil.Bytes
|
Data hexutil.Bytes
|
||||||
BlockNumber hexutil.Uint64
|
BlockNumber hexutil.Uint64
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue