github.com/vantum/vantum@v0.0.0-20180815184342-fe37d5f7a990/tests/gen_stlog.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package tests 4 5 import ( 6 "encoding/json" 7 8 "github.com/vantum/vantum/common" 9 "github.com/vantum/vantum/common/hexutil" 10 ) 11 12 var _ = (*stLogMarshaling)(nil) 13 14 func (s stLog) MarshalJSON() ([]byte, error) { 15 type stLog struct { 16 Address common.UnprefixedAddress `json:"address"` 17 Data hexutil.Bytes `json:"data"` 18 Topics []common.UnprefixedHash `json:"topics"` 19 Bloom string `json:"bloom"` 20 } 21 var enc stLog 22 enc.Address = common.UnprefixedAddress(s.Address) 23 enc.Data = s.Data 24 if s.Topics != nil { 25 enc.Topics = make([]common.UnprefixedHash, len(s.Topics)) 26 for k, v := range s.Topics { 27 enc.Topics[k] = common.UnprefixedHash(v) 28 } 29 } 30 enc.Bloom = s.Bloom 31 return json.Marshal(&enc) 32 } 33 34 func (s *stLog) UnmarshalJSON(input []byte) error { 35 type stLog struct { 36 Address *common.UnprefixedAddress `json:"address"` 37 Data hexutil.Bytes `json:"data"` 38 Topics []common.UnprefixedHash `json:"topics"` 39 Bloom *string `json:"bloom"` 40 } 41 var dec stLog 42 if err := json.Unmarshal(input, &dec); err != nil { 43 return err 44 } 45 if dec.Address != nil { 46 s.Address = common.Address(*dec.Address) 47 } 48 if dec.Data != nil { 49 s.Data = dec.Data 50 } 51 if dec.Topics != nil { 52 s.Topics = make([]common.Hash, len(dec.Topics)) 53 for k, v := range dec.Topics { 54 s.Topics[k] = common.Hash(v) 55 } 56 } 57 if dec.Bloom != nil { 58 s.Bloom = *dec.Bloom 59 } 60 return nil 61 }