-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge changes from topic 'consortium-stack'
* changes: [FAB-2735] (PA) Clean up config mocks [FAB-2723] (PA) Remove old ChainCreationPolicyName [FAB-1302] (PA) Add channel create authorization [FAB-2783] (PA) configtxgen specify admin principl [FAB-2703] (PA) Expose committed configEnvelope [FAB-2702] (PA) Specify consortium in chan config [FAB-2646] (PA) Create consortium configuration
- Loading branch information
Showing
54 changed files
with
1,329 additions
and
651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hyperledger/fabric/common/config/msp" | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
) | ||
|
||
// ConsortiumProtos holds the config protos for the consortium config | ||
type ConsortiumProtos struct { | ||
ChannelCreationPolicy *cb.Policy | ||
} | ||
|
||
// ConsortiumGroup stores the set of Consortium | ||
type ConsortiumGroup struct { | ||
*Proposer | ||
*ConsortiumConfig | ||
|
||
mspConfig *msp.MSPConfigHandler | ||
consortiumsGroup *ConsortiumsGroup | ||
} | ||
|
||
// NewConsortiumGroup creates a new *ConsortiumGroup | ||
func NewConsortiumGroup(consortiumsGroup *ConsortiumsGroup) *ConsortiumGroup { | ||
cg := &ConsortiumGroup{ | ||
mspConfig: msp.NewMSPConfigHandler(), | ||
consortiumsGroup: consortiumsGroup, | ||
} | ||
cg.Proposer = NewProposer(cg) | ||
return cg | ||
} | ||
|
||
// NewGroup returns a Consortium instance | ||
func (cg *ConsortiumGroup) NewGroup(name string) (ValueProposer, error) { | ||
return NewOrganizationGroup(name, cg.mspConfig), nil | ||
} | ||
|
||
// Allocate returns the resources for a new config proposal | ||
func (cg *ConsortiumGroup) Allocate() Values { | ||
return NewConsortiumConfig(cg) | ||
} | ||
|
||
// BeginValueProposals calls through to Proposer after calling into the MSP config Handler | ||
func (cg *ConsortiumGroup) BeginValueProposals(tx interface{}, groups []string) (ValueDeserializer, []ValueProposer, error) { | ||
cg.mspConfig.BeginConfig(tx) | ||
return cg.Proposer.BeginValueProposals(tx, groups) | ||
} | ||
|
||
// PreCommit intercepts the precommit request and commits the MSP config handler before calling the underlying proposer | ||
func (cg *ConsortiumGroup) PreCommit(tx interface{}) error { | ||
err := cg.mspConfig.PreCommit(tx) | ||
if err != nil { | ||
return err | ||
} | ||
return cg.Proposer.PreCommit(tx) | ||
} | ||
|
||
// RollbackProposals intercepts the rollback request and commits the MSP config handler before calling the underlying proposer | ||
func (cg *ConsortiumGroup) RollbackProposals(tx interface{}) { | ||
cg.mspConfig.RollbackProposals(tx) | ||
cg.Proposer.RollbackProposals(tx) | ||
} | ||
|
||
// CommitProposals intercepts the commit request and commits the MSP config handler before calling the underlying proposer | ||
func (cg *ConsortiumGroup) CommitProposals(tx interface{}) { | ||
cg.mspConfig.CommitProposals(tx) | ||
cg.Proposer.CommitProposals(tx) | ||
} | ||
|
||
// ConsortiumConfig holds the consoritums configuration information | ||
type ConsortiumConfig struct { | ||
*standardValues | ||
protos *ConsortiumProtos | ||
orgs map[string]*OrganizationGroup | ||
|
||
consortiumGroup *ConsortiumGroup | ||
} | ||
|
||
// NewConsortiumConfig creates a new instance of the consoritums config | ||
func NewConsortiumConfig(cg *ConsortiumGroup) *ConsortiumConfig { | ||
cc := &ConsortiumConfig{ | ||
protos: &ConsortiumProtos{}, | ||
orgs: make(map[string]*OrganizationGroup), | ||
consortiumGroup: cg, | ||
} | ||
var err error | ||
cc.standardValues, err = NewStandardValues(cc.protos) | ||
if err != nil { | ||
logger.Panicf("Programming error: %s", err) | ||
} | ||
return cc | ||
} | ||
|
||
// Organizations returns the set of organizations in the consortium | ||
func (cc *ConsortiumConfig) Organizations() map[string]*OrganizationGroup { | ||
return cc.orgs | ||
} | ||
|
||
// CreationPolicy returns the policy structure used to validate | ||
// the channel creation | ||
func (cc *ConsortiumConfig) ChannelCreationPolicy() *cb.Policy { | ||
return cc.protos.ChannelCreationPolicy | ||
} | ||
|
||
// Commit commits the ConsortiumConfig | ||
func (cc *ConsortiumConfig) Commit() { | ||
cc.consortiumGroup.ConsortiumConfig = cc | ||
} | ||
|
||
// Validate builds the Consortium map | ||
func (cc *ConsortiumConfig) Validate(tx interface{}, groups map[string]ValueProposer) error { | ||
var ok bool | ||
for key, group := range groups { | ||
cc.orgs[key], ok = group.(*OrganizationGroup) | ||
if !ok { | ||
return fmt.Errorf("Unexpected group type: %T", group) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.