github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/hyperledger/fabric-config/protolator/protoext/commonext/configuration.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  	"github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/ordererext"
    12  	"github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/peerext"
    13  
    14  	"github.com/golang/protobuf/proto"
    15  	"github.com/hyperledger/fabric-protos-go/common"
    16  	"github.com/hyperledger/fabric-protos-go/msp"
    17  )
    18  
    19  type DynamicChannelGroup struct {
    20  	*common.ConfigGroup
    21  }
    22  
    23  func (dcg *DynamicChannelGroup) DynamicMapFields() []string {
    24  	return []string{"values", "groups"}
    25  }
    26  
    27  func (dcg *DynamicChannelGroup) Underlying() proto.Message {
    28  	return dcg.ConfigGroup
    29  }
    30  
    31  func (dcg *DynamicChannelGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
    32  	switch name {
    33  	case "groups":
    34  		cg, ok := base.(*common.ConfigGroup)
    35  		if !ok {
    36  			return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
    37  		}
    38  
    39  		switch key {
    40  		case "Consortiums":
    41  			return &DynamicConsortiumsGroup{ConfigGroup: cg}, nil
    42  		case "Orderer":
    43  			return &ordererext.DynamicOrdererGroup{ConfigGroup: cg}, nil
    44  		case "Application":
    45  			return &peerext.DynamicApplicationGroup{ConfigGroup: cg}, nil
    46  		default:
    47  			return nil, fmt.Errorf("unknown channel group sub-group '%s'", key)
    48  		}
    49  	case "values":
    50  		cv, ok := base.(*common.ConfigValue)
    51  		if !ok {
    52  			return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
    53  		}
    54  		return &DynamicChannelConfigValue{
    55  			ConfigValue: cv,
    56  			name:        key,
    57  		}, nil
    58  	default:
    59  		return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
    60  	}
    61  }
    62  
    63  type DynamicChannelConfigValue struct {
    64  	*common.ConfigValue
    65  	name string
    66  }
    67  
    68  func (dccv *DynamicChannelConfigValue) StaticallyOpaqueFields() []string {
    69  	return []string{"value"}
    70  }
    71  
    72  func (dccv *DynamicChannelConfigValue) Underlying() proto.Message {
    73  	return dccv.ConfigValue
    74  }
    75  
    76  func (dccv *DynamicChannelConfigValue) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
    77  	if name != "value" {
    78  		return nil, fmt.Errorf("not a marshaled field: %s", name)
    79  	}
    80  	switch dccv.name {
    81  	case "HashingAlgorithm":
    82  		return &common.HashingAlgorithm{}, nil
    83  	case "BlockDataHashingStructure":
    84  		return &common.BlockDataHashingStructure{}, nil
    85  	case "OrdererAddresses":
    86  		return &common.OrdererAddresses{}, nil
    87  	case "Consortium":
    88  		return &common.Consortium{}, nil
    89  	case "Capabilities":
    90  		return &common.Capabilities{}, nil
    91  	default:
    92  		return nil, fmt.Errorf("unknown Channel ConfigValue name: %s", dccv.name)
    93  	}
    94  }
    95  
    96  type DynamicConsortiumsGroup struct {
    97  	*common.ConfigGroup
    98  }
    99  
   100  func (dcg *DynamicConsortiumsGroup) Underlying() proto.Message {
   101  	return dcg.ConfigGroup
   102  }
   103  
   104  func (dcg *DynamicConsortiumsGroup) DynamicMapFields() []string {
   105  	return []string{"values", "groups"}
   106  }
   107  
   108  func (dcg *DynamicConsortiumsGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
   109  	switch name {
   110  	case "groups":
   111  		cg, ok := base.(*common.ConfigGroup)
   112  		if !ok {
   113  			return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
   114  		}
   115  
   116  		return &DynamicConsortiumGroup{
   117  			ConfigGroup: cg,
   118  		}, nil
   119  	case "values":
   120  		return nil, fmt.Errorf("Consortiums currently support no config values")
   121  	default:
   122  		return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
   123  	}
   124  }
   125  
   126  type DynamicConsortiumGroup struct {
   127  	*common.ConfigGroup
   128  }
   129  
   130  func (dcg *DynamicConsortiumGroup) Underlying() proto.Message {
   131  	return dcg.ConfigGroup
   132  }
   133  
   134  func (dcg *DynamicConsortiumGroup) DynamicMapFields() []string {
   135  	return []string{"values", "groups"}
   136  }
   137  
   138  func (dcg *DynamicConsortiumGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
   139  	switch name {
   140  	case "groups":
   141  		cg, ok := base.(*common.ConfigGroup)
   142  		if !ok {
   143  			return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
   144  		}
   145  		return &DynamicConsortiumOrgGroup{
   146  			ConfigGroup: cg,
   147  		}, nil
   148  	case "values":
   149  		cv, ok := base.(*common.ConfigValue)
   150  		if !ok {
   151  			return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
   152  		}
   153  
   154  		return &DynamicConsortiumConfigValue{
   155  			ConfigValue: cv,
   156  			name:        key,
   157  		}, nil
   158  	default:
   159  		return nil, fmt.Errorf("not a dynamic orderer map field: %s", name)
   160  	}
   161  }
   162  
   163  type DynamicConsortiumConfigValue struct {
   164  	*common.ConfigValue
   165  	name string
   166  }
   167  
   168  func (dccv *DynamicConsortiumConfigValue) Underlying() proto.Message {
   169  	return dccv.ConfigValue
   170  }
   171  
   172  func (dccv *DynamicConsortiumConfigValue) VariablyOpaqueFields() []string {
   173  	return []string{"value"}
   174  }
   175  
   176  func (dccv *DynamicConsortiumConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
   177  	if name != "value" {
   178  		return nil, fmt.Errorf("not a marshaled field: %s", name)
   179  	}
   180  	switch dccv.name {
   181  	case "ChannelCreationPolicy":
   182  		return &common.Policy{}, nil
   183  	default:
   184  		return nil, fmt.Errorf("unknown Consortium ConfigValue name: %s", dccv.name)
   185  	}
   186  }
   187  
   188  type DynamicConsortiumOrgGroup struct {
   189  	*common.ConfigGroup
   190  }
   191  
   192  func (dcg *DynamicConsortiumOrgGroup) Underlying() proto.Message {
   193  	return dcg.ConfigGroup
   194  }
   195  
   196  func (dcg *DynamicConsortiumOrgGroup) DynamicMapFields() []string {
   197  	return []string{"groups", "values"}
   198  }
   199  
   200  func (dcg *DynamicConsortiumOrgGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
   201  	switch name {
   202  	case "groups":
   203  		return nil, fmt.Errorf("ConsortiumOrg groups do not support sub groups")
   204  	case "values":
   205  		cv, ok := base.(*common.ConfigValue)
   206  		if !ok {
   207  			return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
   208  		}
   209  
   210  		return &DynamicConsortiumOrgConfigValue{
   211  			ConfigValue: cv,
   212  			name:        key,
   213  		}, nil
   214  	default:
   215  		return nil, fmt.Errorf("not a dynamic orderer map field: %s", name)
   216  	}
   217  }
   218  
   219  type DynamicConsortiumOrgConfigValue struct {
   220  	*common.ConfigValue
   221  	name string
   222  }
   223  
   224  func (dcocv *DynamicConsortiumOrgConfigValue) Underlying() proto.Message {
   225  	return dcocv.ConfigValue
   226  }
   227  
   228  func (dcocv *DynamicConsortiumOrgConfigValue) StaticallyOpaqueFields() []string {
   229  	return []string{"value"}
   230  }
   231  
   232  func (dcocv *DynamicConsortiumOrgConfigValue) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
   233  	if name != "value" {
   234  		return nil, fmt.Errorf("not a marshaled field: %s", name)
   235  	}
   236  	switch dcocv.name {
   237  	case "MSP":
   238  		return &msp.MSPConfig{}, nil
   239  	default:
   240  		return nil, fmt.Errorf("unknown Consortium Org ConfigValue name: %s", dcocv.name)
   241  	}
   242  }