@@ -17,14 +17,10 @@ limitations under the License.
17
17
package config
18
18
19
19
import (
20
- "fmt"
21
-
22
20
api "github.com/hyperledger/fabric/common/configvalues"
23
21
mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
24
- cb "github.com/hyperledger/fabric/protos/common"
25
22
pb "github.com/hyperledger/fabric/protos/peer"
26
23
27
- "github.com/golang/protobuf/proto"
28
24
logging "github.com/op/go-logging"
29
25
)
30
26
@@ -34,82 +30,66 @@ const (
34
30
AnchorPeersKey = "AnchorPeers"
35
31
)
36
32
37
- type applicationOrgConfig struct {
38
- anchorPeers [] * pb.AnchorPeer
33
+ type ApplicationOrgProtos struct {
34
+ AnchorPeers * pb.AnchorPeers
39
35
}
40
36
41
- // SharedConfigImpl is an implementation of Manager and configtx.ConfigHandler
42
- // In general, it should only be referenced as an Impl for the configtx.Manager
43
37
type ApplicationOrgConfig struct {
44
- * OrganizationGroup
45
- pendingConfig * applicationOrgConfig
46
- config * applicationOrgConfig
38
+ * OrganizationConfig
39
+ protos * ApplicationOrgProtos
40
+
41
+ applicationOrgGroup * ApplicationOrgGroup
42
+ }
47
43
48
- mspConfig * mspconfig.MSPConfigHandler
44
+ // ApplicationOrgGroup defines the configuration for an application org
45
+ type ApplicationOrgGroup struct {
46
+ * Proposer
47
+ * OrganizationGroup
48
+ * ApplicationOrgConfig
49
49
}
50
50
51
- // NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
52
- func NewApplicationOrgConfig (id string , mspConfig * mspconfig.MSPConfigHandler ) * ApplicationOrgConfig {
53
- return & ApplicationOrgConfig {
51
+ // NewApplicationOrgGroup creates a new ApplicationOrgGroup
52
+ func NewApplicationOrgGroup (id string , mspConfig * mspconfig.MSPConfigHandler ) * ApplicationOrgGroup {
53
+ aog := & ApplicationOrgGroup {
54
54
OrganizationGroup : NewOrganizationGroup (id , mspConfig ),
55
- config : & applicationOrgConfig {},
56
55
}
56
+ aog .Proposer = NewProposer (aog )
57
+ return aog
57
58
}
58
59
59
60
// AnchorPeers returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
60
- func (oc * ApplicationOrgConfig ) AnchorPeers () []* pb.AnchorPeer {
61
- return oc . config . anchorPeers
61
+ func (aog * ApplicationOrgConfig ) AnchorPeers () []* pb.AnchorPeer {
62
+ return aog . protos . AnchorPeers . AnchorPeers
62
63
}
63
64
64
- // BeginValueProposals is used to start a new config proposal
65
- func (oc * ApplicationOrgConfig ) BeginValueProposals (groups []string ) ([]api.ValueProposer , error ) {
66
- logger .Debugf ("Beginning a possible new org config" )
67
- if len (groups ) != 0 {
68
- return nil , fmt .Errorf ("ApplicationGroup does not support subgroups" )
69
- }
70
- if oc .pendingConfig != nil {
71
- logger .Panicf ("Programming error, cannot call begin in the middle of a proposal" )
72
- }
73
- oc .pendingConfig = & applicationOrgConfig {}
74
- return oc .OrganizationGroup .BeginValueProposals (groups )
65
+ func (aog * ApplicationOrgGroup ) Allocate () Values {
66
+ return NewApplicationOrgConfig (aog )
75
67
}
76
68
77
- // RollbackProposals is used to abandon a new config proposal
78
- func (oc * ApplicationOrgConfig ) RollbackProposals () {
79
- logger .Debugf ("Rolling back proposed org config" )
80
- oc .pendingConfig = nil
81
- oc .OrganizationGroup .RollbackProposals ()
69
+ func (aoc * ApplicationOrgConfig ) Commit () {
70
+ aoc .applicationOrgGroup .ApplicationOrgConfig = aoc
71
+ aoc .OrganizationConfig .Commit ()
82
72
}
83
73
84
- // CommitProposals is used to commit a new config proposal
85
- func (oc * ApplicationOrgConfig ) CommitProposals () {
86
- logger .Debugf ("Committing new org config" )
87
- if oc .pendingConfig == nil {
88
- logger .Panicf ("Programming error, cannot call commit without an existing proposal" )
89
- }
90
- oc .config = oc .pendingConfig
91
- oc .pendingConfig = nil
92
- oc .OrganizationGroup .CommitProposals ()
93
- }
74
+ func NewApplicationOrgConfig (aog * ApplicationOrgGroup ) * ApplicationOrgConfig {
75
+ aoc := & ApplicationOrgConfig {
76
+ protos : & ApplicationOrgProtos {},
77
+ OrganizationConfig : NewOrganizationConfig (aog .OrganizationGroup ),
94
78
95
- // ProposeValue is used to add new config to the config proposal
96
- func (oc * ApplicationOrgConfig ) ProposeValue (key string , configValue * cb.ConfigValue ) error {
97
- switch key {
98
- case AnchorPeersKey :
99
- anchorPeers := & pb.AnchorPeers {}
100
- if err := proto .Unmarshal (configValue .Value , anchorPeers ); err != nil {
101
- return fmt .Errorf ("Unmarshaling error for %s: %s" , key , err )
102
- }
103
- if logger .IsEnabledFor (logging .DEBUG ) {
104
- logger .Debugf ("Setting %s to %v" , key , anchorPeers .AnchorPeers )
105
- }
106
- oc .pendingConfig .anchorPeers = anchorPeers .AnchorPeers
107
- default :
108
- return oc .OrganizationGroup .ProposeValue (key , configValue )
79
+ applicationOrgGroup : aog ,
80
+ }
81
+ var err error
82
+ aoc .standardValues , err = NewStandardValues (aoc .protos , aoc .OrganizationConfig .protos )
83
+ if err != nil {
84
+ logger .Panicf ("Programming error: %s" , err )
109
85
}
110
86
111
- return nil
87
+ return aoc
112
88
}
113
89
114
- // PreCommit returns nil
115
- func (c * ApplicationOrgConfig ) PreCommit () error { return nil }
90
+ func (aoc * ApplicationOrgConfig ) Validate (groups map [string ]api.ValueProposer ) error {
91
+ if logger .IsEnabledFor (logging .DEBUG ) {
92
+ logger .Debugf ("Anchor peers for org %s are %v" , aoc .applicationOrgGroup .name , aoc .protos .AnchorPeers )
93
+ }
94
+ return aoc .OrganizationConfig .Validate (groups )
95
+ }
0 commit comments