github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/whisper/whisperv6/gen_criteria_json.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 // 10 11 package whisperv6 12 13 import ( 14 "encoding/json" 15 16 "github.com/ethereum/go-ethereum/common/hexutil" 17 ) 18 19 var _ = (*criteriaOverride)(nil) 20 21 // 22 func (c Criteria) MarshalJSON() ([]byte, error) { 23 type Criteria struct { 24 SymKeyID string `json:"symKeyID"` 25 PrivateKeyID string `json:"privateKeyID"` 26 Sig hexutil.Bytes `json:"sig"` 27 MinPow float64 `json:"minPow"` 28 Topics []TopicType `json:"topics"` 29 AllowP2P bool `json:"allowP2P"` 30 } 31 var enc Criteria 32 enc.SymKeyID = c.SymKeyID 33 enc.PrivateKeyID = c.PrivateKeyID 34 enc.Sig = c.Sig 35 enc.MinPow = c.MinPow 36 enc.Topics = c.Topics 37 enc.AllowP2P = c.AllowP2P 38 return json.Marshal(&enc) 39 } 40 41 // 42 func (c *Criteria) UnmarshalJSON(input []byte) error { 43 type Criteria struct { 44 SymKeyID *string `json:"symKeyID"` 45 PrivateKeyID *string `json:"privateKeyID"` 46 Sig *hexutil.Bytes `json:"sig"` 47 MinPow *float64 `json:"minPow"` 48 Topics []TopicType `json:"topics"` 49 AllowP2P *bool `json:"allowP2P"` 50 } 51 var dec Criteria 52 if err := json.Unmarshal(input, &dec); err != nil { 53 return err 54 } 55 if dec.SymKeyID != nil { 56 c.SymKeyID = *dec.SymKeyID 57 } 58 if dec.PrivateKeyID != nil { 59 c.PrivateKeyID = *dec.PrivateKeyID 60 } 61 if dec.Sig != nil { 62 c.Sig = *dec.Sig 63 } 64 if dec.MinPow != nil { 65 c.MinPow = *dec.MinPow 66 } 67 if dec.Topics != nil { 68 c.Topics = dec.Topics 69 } 70 if dec.AllowP2P != nil { 71 c.AllowP2P = *dec.AllowP2P 72 } 73 return nil 74 }