github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/protos/common/configtx.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8                   http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package common
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/golang/protobuf/proto"
    23  )
    24  
    25  func NewConfigGroup() *ConfigGroup {
    26  	return &ConfigGroup{
    27  		Groups:   make(map[string]*ConfigGroup),
    28  		Values:   make(map[string]*ConfigValue),
    29  		Policies: make(map[string]*ConfigPolicy),
    30  	}
    31  }
    32  
    33  func (cue *ConfigUpdateEnvelope) StaticallyOpaqueFields() []string {
    34  	return []string{"config_update"}
    35  }
    36  
    37  func (cue *ConfigUpdateEnvelope) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
    38  	if name != cue.StaticallyOpaqueFields()[0] {
    39  		return nil, fmt.Errorf("Not a marshaled field: %s", name)
    40  	}
    41  	return &ConfigUpdate{}, nil
    42  }
    43  
    44  func (cs *ConfigSignature) StaticallyOpaqueFields() []string {
    45  	return []string{"signature_header"}
    46  }
    47  
    48  func (cs *ConfigSignature) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
    49  	if name != cs.StaticallyOpaqueFields()[0] {
    50  		return nil, fmt.Errorf("Not a marshaled field: %s", name)
    51  	}
    52  	return &SignatureHeader{}, nil
    53  }
    54  
    55  func (c *Config) DynamicFields() []string {
    56  	return []string{"channel_group"}
    57  }
    58  
    59  func (c *Config) DynamicFieldProto(name string, base proto.Message) (proto.Message, error) {
    60  	if name != c.DynamicFields()[0] {
    61  		return nil, fmt.Errorf("Not a dynamic field: %s", name)
    62  	}
    63  
    64  	cg, ok := base.(*ConfigGroup)
    65  	if !ok {
    66  		return nil, fmt.Errorf("Config must embed a config group as its dynamic field")
    67  	}
    68  
    69  	return &DynamicChannelGroup{
    70  		ConfigGroup: cg,
    71  	}, nil
    72  }
    73  
    74  func (c *ConfigUpdate) DynamicFields() []string {
    75  	return []string{"read_set", "write_set"}
    76  }
    77  
    78  func (c *ConfigUpdate) DynamicFieldProto(name string, base proto.Message) (proto.Message, error) {
    79  	if name != c.DynamicFields()[0] && name != c.DynamicFields()[1] {
    80  		return nil, fmt.Errorf("Not a dynamic field: %s", name)
    81  	}
    82  
    83  	cg, ok := base.(*ConfigGroup)
    84  	if !ok {
    85  		return nil, fmt.Errorf("Expected base to be *ConfigGroup, got %T", base)
    86  	}
    87  
    88  	return &DynamicChannelGroup{
    89  		ConfigGroup: cg,
    90  	}, nil
    91  }
    92  
    93  func (cv *ConfigValue) VariablyOpaqueFields() []string {
    94  	return []string{"value"}
    95  }
    96  
    97  func (cv *ConfigValue) Underlying() proto.Message {
    98  	return cv
    99  }
   100  
   101  func (cg *ConfigGroup) DynamicMapFields() []string {
   102  	return []string{"groups", "values"}
   103  }
   104  
   105  func (cg *ConfigGroup) Underlying() proto.Message {
   106  	return cg
   107  }