aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/gen_log_json.go
blob: ef2cdfd890b184d80d5c2c81ecb72912aaee550a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// generated by github.com/fjl/gencodec, do not edit.

package types

import (
    "encoding/json"
    "errors"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/common/hexutil"
)

func (l *Log) MarshalJSON() ([]byte, error) {
    type LogJSON struct {
        Address     *common.Address `json:"address"`
        Topics      []common.Hash   `json:"topics"`
        Data        hexutil.Bytes   `json:"data"`
        BlockNumber *hexutil.Uint64 `json:"blockNumber" optional:"yes"`
        TxHash      *common.Hash    `json:"transactionHash"`
        TxIndex     *hexutil.Uint   `json:"transactionIndex"`
        BlockHash   *common.Hash    `json:"blockHash" optional:"yes"`
        Index       *hexutil.Uint   `json:"logIndex"`
        Removed     *bool           `json:"removed" optional:"yes"`
    }
    var enc LogJSON
    enc.Address = &l.Address
    enc.Topics = l.Topics
    enc.Data = l.Data
    enc.BlockNumber = (*hexutil.Uint64)(&l.BlockNumber)
    enc.TxHash = &l.TxHash
    enc.TxIndex = (*hexutil.Uint)(&l.TxIndex)
    enc.BlockHash = &l.BlockHash
    enc.Index = (*hexutil.Uint)(&l.Index)
    enc.Removed = &l.Removed
    return json.Marshal(&enc)
}

func (l *Log) UnmarshalJSON(input []byte) error {
    type LogJSON struct {
        Address     *common.Address `json:"address"`
        Topics      []common.Hash   `json:"topics"`
        Data        hexutil.Bytes   `json:"data"`
        BlockNumber *hexutil.Uint64 `json:"blockNumber" optional:"yes"`
        TxHash      *common.Hash    `json:"transactionHash"`
        TxIndex     *hexutil.Uint   `json:"transactionIndex"`
        BlockHash   *common.Hash    `json:"blockHash" optional:"yes"`
        Index       *hexutil.Uint   `json:"logIndex"`
        Removed     *bool           `json:"removed" optional:"yes"`
    }
    var dec LogJSON
    if err := json.Unmarshal(input, &dec); err != nil {
        return err
    }
    var x Log
    if dec.Address == nil {
        return errors.New("missing required field 'address' for Log")
    }
    x.Address = *dec.Address
    if dec.Topics == nil {
        return errors.New("missing required field 'topics' for Log")
    }
    x.Topics = dec.Topics
    if dec.Data == nil {
        return errors.New("missing required field 'data' for Log")
    }
    x.Data = dec.Data
    if dec.BlockNumber != nil {
        x.BlockNumber = uint64(*dec.BlockNumber)
    }
    if dec.TxHash == nil {
        return errors.New("missing required field 'transactionHash' for Log")
    }
    x.TxHash = *dec.TxHash
    if dec.TxIndex == nil {
        return errors.New("missing required field 'transactionIndex' for Log")
    }
    x.TxIndex = uint(*dec.TxIndex)
    if dec.BlockHash != nil {
        x.BlockHash = *dec.BlockHash
    }
    if dec.Index == nil {
        return errors.New("missing required field 'logIndex' for Log")
    }
    x.Index = uint(*dec.Index)
    if dec.Removed != nil {
        x.Removed = *dec.Removed
    }
    *l = x
    return nil
}