-
Notifications
You must be signed in to change notification settings - Fork 92
/
applicationorg.go
76 lines (61 loc) · 1.95 KB
/
applicationorg.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
/*
Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
Please review third_party pinning scripts and patches for more details.
*/
package channelconfig
import (
"fmt"
cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/pkg/errors"
)
const (
// AnchorPeersKey is the key name for the AnchorPeers ConfigValue
AnchorPeersKey = "AnchorPeers"
)
// ApplicationOrgProtos are deserialized from the config
type ApplicationOrgProtos struct {
AnchorPeers *pb.AnchorPeers
}
// ApplicationOrgConfig defines the configuration for an application org
type ApplicationOrgConfig struct {
*OrganizationConfig
protos *ApplicationOrgProtos
name string
}
// NewApplicationOrgConfig creates a new config for an application org
func NewApplicationOrgConfig(id string, orgGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ApplicationOrgConfig, error) {
if len(orgGroup.Groups) > 0 {
return nil, fmt.Errorf("ApplicationOrg config does not allow sub-groups")
}
protos := &ApplicationOrgProtos{}
orgProtos := &OrganizationProtos{}
if err := DeserializeProtoValuesFromGroup(orgGroup, protos, orgProtos); err != nil {
return nil, errors.Wrap(err, "failed to deserialize values")
}
aoc := &ApplicationOrgConfig{
name: id,
protos: protos,
OrganizationConfig: &OrganizationConfig{
name: id,
protos: orgProtos,
mspConfigHandler: mspConfig,
},
}
if err := aoc.Validate(); err != nil {
return nil, err
}
return aoc, nil
}
// AnchorPeers returns the list of anchor peers of this Organization
func (aog *ApplicationOrgConfig) AnchorPeers() []*pb.AnchorPeer {
return aog.protos.AnchorPeers.AnchorPeers
}
func (aoc *ApplicationOrgConfig) Validate() error {
logger.Debugf("Anchor peers for org %s are %v", aoc.name, aoc.protos.AnchorPeers)
return aoc.OrganizationConfig.Validate()
}