-
Notifications
You must be signed in to change notification settings - Fork 0
/
consortium.go
61 lines (49 loc) · 1.67 KB
/
consortium.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package channelconfig
import (
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/pkg/errors"
)
const (
// ChannelCreationPolicyKey is the key used in the consortium config to denote the policy
// to be used in evaluating whether a channel creation request is authorized
ChannelCreationPolicyKey = "ChannelCreationPolicy"
)
// ConsortiumProtos holds the config protos for the consortium config
type ConsortiumProtos struct {
ChannelCreationPolicy *cb.Policy
}
// ConsortiumConfig holds the consortium's configuration information
type ConsortiumConfig struct {
protos *ConsortiumProtos
orgs map[string]Org
}
// NewConsortiumConfig creates a new instance of the consortium's config
func NewConsortiumConfig(consortiumGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ConsortiumConfig, error) {
cc := &ConsortiumConfig{
protos: &ConsortiumProtos{},
orgs: make(map[string]Org),
}
if err := DeserializeProtoValuesFromGroup(consortiumGroup, cc.protos); err != nil {
return nil, errors.Wrap(err, "failed to deserialize values")
}
for orgName, orgGroup := range consortiumGroup.Groups {
var err error
if cc.orgs[orgName], err = NewOrganizationConfig(orgName, orgGroup, mspConfig); err != nil {
return nil, err
}
}
return cc, nil
}
// Organizations returns the set of organizations in the consortium
func (cc *ConsortiumConfig) Organizations() map[string]Org {
return cc.orgs
}
// CreationPolicy returns the policy structure used to validate
// the channel creation
func (cc *ConsortiumConfig) ChannelCreationPolicy() *cb.Policy {
return cc.protos.ChannelCreationPolicy
}