github.com/amazechain/amc@v0.1.3/internal/avm/types/logs.go (about) 1 package types 2 3 import ( 4 "encoding/json" 5 "errors" 6 "github.com/amazechain/amc/common/hexutil" 7 "github.com/amazechain/amc/internal/avm/common" 8 ) 9 10 type Log struct { 11 // Consensus fields: 12 // address of the contract that generated the event 13 Address common.Address `json:"address" gencodec:"required"` 14 // list of topics provided by the contract. 15 Topics []common.Hash `json:"topics" gencodec:"required"` 16 // supplied by the contract, usually ABI-encoded 17 Data []byte `json:"data" gencodec:"required"` 18 19 // Derived fields. These fields are filled in by the node 20 // but not secured by consensus. 21 // block in which the transaction was included 22 BlockNumber uint64 `json:"blockNumber"` 23 // hash of the transaction 24 TxHash common.Hash `json:"transactionHash" gencodec:"required"` 25 // index of the transaction in the block 26 TxIndex uint `json:"transactionIndex" gencodec:"required"` 27 // hash of the block in which the transaction was included 28 BlockHash common.Hash `json:"blockHash"` 29 // index of the log in the receipt 30 Index uint `json:"logIndex" gencodec:"required"` 31 32 // The Removed field is true if this log was reverted due to a chain reorganisation. 33 // You must pay attention to this field if you receive logs through a filter query. 34 Removed bool `json:"removed"` 35 } 36 37 // MarshalJSON marshals as JSON. 38 func (l Log) MarshalJSON() ([]byte, error) { 39 type Log struct { 40 Address common.Address `json:"address" gencodec:"required"` 41 Topics []common.Hash `json:"topics" gencodec:"required"` 42 Data hexutil.Bytes `json:"data" gencodec:"required"` 43 BlockNumber hexutil.Uint64 `json:"blockNumber"` 44 TxHash common.Hash `json:"transactionHash" gencodec:"required"` 45 TxIndex hexutil.Uint `json:"transactionIndex"` 46 BlockHash common.Hash `json:"blockHash"` 47 Index hexutil.Uint `json:"logIndex"` 48 Removed bool `json:"removed"` 49 } 50 var enc Log 51 enc.Address = l.Address 52 enc.Topics = l.Topics 53 enc.Data = l.Data 54 enc.BlockNumber = hexutil.Uint64(l.BlockNumber) 55 enc.TxHash = l.TxHash 56 enc.TxIndex = hexutil.Uint(l.TxIndex) 57 enc.BlockHash = l.BlockHash 58 enc.Index = hexutil.Uint(l.Index) 59 enc.Removed = l.Removed 60 return json.Marshal(&enc) 61 } 62 63 // UnmarshalJSON unmarshals from JSON. 64 func (l *Log) UnmarshalJSON(input []byte) error { 65 type Log struct { 66 Address *common.Address `json:"address" gencodec:"required"` 67 Topics []common.Hash `json:"topics" gencodec:"required"` 68 Data *hexutil.Bytes `json:"data" gencodec:"required"` 69 BlockNumber *hexutil.Uint64 `json:"blockNumber"` 70 TxHash *common.Hash `json:"transactionHash" gencodec:"required"` 71 TxIndex *hexutil.Uint `json:"transactionIndex"` 72 BlockHash *common.Hash `json:"blockHash"` 73 Index *hexutil.Uint `json:"logIndex"` 74 Removed *bool `json:"removed"` 75 } 76 var dec Log 77 if err := json.Unmarshal(input, &dec); err != nil { 78 return err 79 } 80 if dec.Address == nil { 81 return errors.New("missing required field 'address' for Log") 82 } 83 l.Address = *dec.Address 84 if dec.Topics == nil { 85 return errors.New("missing required field 'topics' for Log") 86 } 87 l.Topics = dec.Topics 88 if dec.Data == nil { 89 return errors.New("missing required field 'data' for Log") 90 } 91 l.Data = *dec.Data 92 if dec.BlockNumber != nil { 93 l.BlockNumber = uint64(*dec.BlockNumber) 94 } 95 if dec.TxHash == nil { 96 return errors.New("missing required field 'transactionHash' for Log") 97 } 98 l.TxHash = *dec.TxHash 99 if dec.TxIndex != nil { 100 l.TxIndex = uint(*dec.TxIndex) 101 } 102 if dec.BlockHash != nil { 103 l.BlockHash = *dec.BlockHash 104 } 105 if dec.Index != nil { 106 l.Index = uint(*dec.Index) 107 } 108 if dec.Removed != nil { 109 l.Removed = *dec.Removed 110 } 111 return nil 112 }