github.com/annchain/OG@v0.0.9/vm/types/log.go (about) 1 // Copyright 2014 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package types 18 19 import ( 20 "github.com/annchain/OG/arefactor/og/types" 21 "github.com/annchain/OG/common" 22 "io" 23 24 "github.com/annchain/OG/common/hexutil" 25 "github.com/annchain/OG/vm/eth/rlp" 26 ) 27 28 //go:generate gencodec -type Log -field-override logMarshaling -out gen_log_json.go 29 30 // Log represents a contract log event. These events are generated by the LOG opcode and 31 // stored/indexed by the node. 32 type Log struct { 33 // Consensus fields: 34 // address of the contract that generated the event 35 Address common.Address `json:"address" gencodec:"required"` 36 // list of topics provided by the contract. 37 Topics types.Hashes `json:"topics" gencodec:"required"` 38 // supplied by the contract, usually ABI-encoded 39 Data []byte `json:"data" gencodec:"required"` 40 41 // Derived fields. These fields are filled in by the node 42 // but not secured by consensus. 43 // block in which the transaction was included 44 SequenceID uint64 `json:"blockNumber"` 45 // hash of the transaction 46 TxHash types.Hash `json:"transactionHash" gencodec:"required"` 47 // index of the transaction in the block 48 TxIndex uint `json:"transactionIndex" gencodec:"required"` 49 // hash of the block in which the transaction was included 50 BlockHash types.Hash `json:"blockHash"` 51 // index of the log in the block 52 Index uint `json:"logIndex" gencodec:"required"` 53 54 // The Removed field is true if this log was reverted due to a chain reorganisation. 55 // You must pay attention to this field if you receive logs through a filter query. 56 Removed bool `json:"removed"` 57 } 58 59 type logMarshaling struct { 60 Data hexutil.Bytes 61 BlockNumber hexutil.Uint64 62 TxIndex hexutil.Uint 63 Index hexutil.Uint 64 } 65 66 type rlpLog struct { 67 Address common.Address 68 Topics types.Hashes 69 Data []byte 70 } 71 72 type rlpStorageLog struct { 73 Address common.Address 74 Topics types.Hashes 75 Data []byte 76 BlockNumber uint64 77 TxHash types.Hash 78 TxIndex uint 79 BlockHash types.Hash 80 Index uint 81 } 82 83 // EncodeRLP implements rlp.Encoder. 84 func (l *Log) EncodeRLP(w io.Writer) error { 85 return rlp.Encode(w, rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data}) 86 } 87 88 // DecodeRLP implements rlp.Decoder. 89 func (l *Log) DecodeRLP(s *rlp.Stream) error { 90 var dec rlpLog 91 err := s.Decode(&dec) 92 if err == nil { 93 l.Address, l.Topics, l.Data = dec.Address, dec.Topics, dec.Data 94 } 95 return err 96 } 97 98 // LogForStorage is a wrapper around a Log that flattens and parses the entire content of 99 // a log including non-consensus fields. 100 type LogForStorage Log 101 102 // EncodeRLP implements rlp.Encoder. 103 func (l *LogForStorage) EncodeRLP(w io.Writer) error { 104 return rlp.Encode(w, rlpStorageLog{ 105 Address: l.Address, 106 Topics: l.Topics, 107 Data: l.Data, 108 BlockNumber: l.SequenceID, 109 TxHash: l.TxHash, 110 TxIndex: l.TxIndex, 111 BlockHash: l.BlockHash, 112 Index: l.Index, 113 }) 114 } 115 116 // DecodeRLP implements rlp.Decoder. 117 func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error { 118 var dec rlpStorageLog 119 err := s.Decode(&dec) 120 if err == nil { 121 *l = LogForStorage{ 122 Address: dec.Address, 123 Topics: dec.Topics, 124 Data: dec.Data, 125 SequenceID: dec.BlockNumber, 126 TxHash: dec.TxHash, 127 TxIndex: dec.TxIndex, 128 BlockHash: dec.BlockHash, 129 Index: dec.Index, 130 } 131 } 132 return err 133 }