github.com/theQRL/go-zond@v0.1.1/beacon/types/gen_syncaggregate_json.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package types 4 5 import ( 6 "encoding/json" 7 "errors" 8 9 "github.com/theQRL/go-zond/common/hexutil" 10 ) 11 12 var _ = (*syncAggregateMarshaling)(nil) 13 14 // MarshalJSON marshals as JSON. 15 func (s SyncAggregate) MarshalJSON() ([]byte, error) { 16 type SyncAggregate struct { 17 Signers hexutil.Bytes `gencodec:"required" json:"sync_committee_bits"` 18 Signature hexutil.Bytes `gencodec:"required" json:"sync_committee_signature"` 19 } 20 var enc SyncAggregate 21 enc.Signers = s.Signers[:] 22 enc.Signature = s.Signature[:] 23 return json.Marshal(&enc) 24 } 25 26 // UnmarshalJSON unmarshals from JSON. 27 func (s *SyncAggregate) UnmarshalJSON(input []byte) error { 28 type SyncAggregate struct { 29 Signers *hexutil.Bytes `gencodec:"required" json:"sync_committee_bits"` 30 Signature *hexutil.Bytes `gencodec:"required" json:"sync_committee_signature"` 31 } 32 var dec SyncAggregate 33 if err := json.Unmarshal(input, &dec); err != nil { 34 return err 35 } 36 if dec.Signers == nil { 37 return errors.New("missing required field 'sync_committee_bits' for SyncAggregate") 38 } 39 if len(*dec.Signers) != len(s.Signers) { 40 return errors.New("field 'sync_committee_bits' has wrong length, need 64 items") 41 } 42 copy(s.Signers[:], *dec.Signers) 43 if dec.Signature == nil { 44 return errors.New("missing required field 'sync_committee_signature' for SyncAggregate") 45 } 46 if len(*dec.Signature) != len(s.Signature) { 47 return errors.New("field 'sync_committee_signature' has wrong length, need 96 items") 48 } 49 copy(s.Signature[:], *dec.Signature) 50 return nil 51 }