github.com/kaituanwang/hyperledger@v2.0.1+incompatible/common/tools/protolator/protoext/commonext/configtx.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package commonext 8 9 import ( 10 "fmt" 11 12 "github.com/golang/protobuf/proto" 13 "github.com/hyperledger/fabric-protos-go/common" 14 ) 15 16 type ConfigUpdateEnvelope struct{ *common.ConfigUpdateEnvelope } 17 18 func (cue *ConfigUpdateEnvelope) Underlying() proto.Message { 19 return cue.ConfigUpdateEnvelope 20 } 21 22 func (cue *ConfigUpdateEnvelope) StaticallyOpaqueFields() []string { 23 return []string{"config_update"} 24 } 25 26 func (cue *ConfigUpdateEnvelope) StaticallyOpaqueFieldProto(name string) (proto.Message, error) { 27 if name != cue.StaticallyOpaqueFields()[0] { 28 return nil, fmt.Errorf("Not a marshaled field: %s", name) 29 } 30 return &common.ConfigUpdate{}, nil 31 } 32 33 type ConfigSignature struct{ *common.ConfigSignature } 34 35 func (cs *ConfigSignature) Underlying() proto.Message { 36 return cs.ConfigSignature 37 } 38 39 func (cs *ConfigSignature) StaticallyOpaqueFields() []string { 40 return []string{"signature_header"} 41 } 42 43 func (cs *ConfigSignature) StaticallyOpaqueFieldProto(name string) (proto.Message, error) { 44 if name != cs.StaticallyOpaqueFields()[0] { 45 return nil, fmt.Errorf("Not a marshaled field: %s", name) 46 } 47 return &common.SignatureHeader{}, nil 48 } 49 50 type Config struct{ *common.Config } 51 52 func (c *Config) Underlying() proto.Message { 53 return c.Config 54 } 55 56 func (c *Config) DynamicFields() []string { 57 return []string{"channel_group"} 58 } 59 60 func (c *Config) DynamicFieldProto(name string, base proto.Message) (proto.Message, error) { 61 if name != c.DynamicFields()[0] { 62 return nil, fmt.Errorf("Not a dynamic field: %s", name) 63 } 64 65 cg, ok := base.(*common.ConfigGroup) 66 if !ok { 67 return nil, fmt.Errorf("Config must embed a config group as its dynamic field") 68 } 69 70 return &DynamicChannelGroup{ConfigGroup: cg}, nil 71 } 72 73 // ConfigUpdateIsolatedDataTypes allows other proto packages to register types for the 74 // the isolated_data field. This is necessary to break import cycles. 75 var ConfigUpdateIsolatedDataTypes = map[string]func(string) proto.Message{} 76 77 type ConfigUpdate struct{ *common.ConfigUpdate } 78 79 func (c *ConfigUpdate) Underlying() proto.Message { 80 return c.ConfigUpdate 81 } 82 83 func (c *ConfigUpdate) StaticallyOpaqueMapFields() []string { 84 return []string{"isolated_data"} 85 } 86 87 func (c *ConfigUpdate) StaticallyOpaqueMapFieldProto(name string, key string) (proto.Message, error) { 88 if name != c.StaticallyOpaqueMapFields()[0] { 89 return nil, fmt.Errorf("Not a statically opaque map field: %s", name) 90 } 91 92 mf, ok := ConfigUpdateIsolatedDataTypes[key] 93 if !ok { 94 return nil, fmt.Errorf("Unknown map key: %s", key) 95 } 96 97 return mf(key), nil 98 } 99 100 func (c *ConfigUpdate) DynamicFields() []string { 101 return []string{"read_set", "write_set"} 102 } 103 104 func (c *ConfigUpdate) DynamicFieldProto(name string, base proto.Message) (proto.Message, error) { 105 if name != c.DynamicFields()[0] && name != c.DynamicFields()[1] { 106 return nil, fmt.Errorf("Not a dynamic field: %s", name) 107 } 108 109 cg, ok := base.(*common.ConfigGroup) 110 if !ok { 111 return nil, fmt.Errorf("Expected base to be *ConfigGroup, got %T", base) 112 } 113 114 return &DynamicChannelGroup{ConfigGroup: cg}, nil 115 }