@@ -26,8 +26,23 @@ import (
2626 "github.com/hyperledger/fabric/msp"
2727 "github.com/hyperledger/fabric/msp/cache"
2828 "github.com/pkg/errors"
29+ "github.com/spf13/viper"
2930)
3031
32+ // LoadLocalMspWithType loads the local MSP with the specified type from the specified directory
33+ func LoadLocalMspWithType (dir string , bccspConfig * factory.FactoryOpts , mspID , mspType string ) error {
34+ if mspID == "" {
35+ return errors .New ("the local MSP must have an ID" )
36+ }
37+
38+ conf , err := msp .GetLocalMspConfigWithType (dir , bccspConfig , mspID , mspType )
39+ if err != nil {
40+ return err
41+ }
42+
43+ return GetLocalMSP ().Setup (conf )
44+ }
45+
3146// LoadLocalMsp loads the local MSP from the specified directory
3247func LoadLocalMsp (dir string , bccspConfig * factory.FactoryOpts , mspID string ) error {
3348 if mspID == "" {
@@ -115,6 +130,23 @@ func GetLocalMSP() msp.MSP {
115130 var lclMsp msp.MSP
116131 var created bool = false
117132 {
133+ // determine the type of MSP (by default, we'll use bccspMSP)
134+ mspType := viper .GetString ("peer.localMspType" )
135+ if mspType == "" {
136+ mspType = msp .ProviderTypeToString (msp .FABRIC )
137+ }
138+
139+ // based on the MSP type, generate the new opts
140+ var newOpts msp.NewOpts
141+ switch mspType {
142+ case msp .ProviderTypeToString (msp .FABRIC ):
143+ newOpts = & msp.BCCSPNewOpts {NewBaseOpts : msp.NewBaseOpts {Version : msp .MSPv1_0 }}
144+ case msp .ProviderTypeToString (msp .IDEMIX ):
145+ newOpts = & msp.IdemixNewOpts {msp.NewBaseOpts {Version : msp .MSPv1_1 }}
146+ default :
147+ panic ("msp type " + mspType + " unknown" )
148+ }
149+
118150 m .Lock ()
119151 defer m .Unlock ()
120152
@@ -123,14 +155,21 @@ func GetLocalMSP() msp.MSP {
123155 var err error
124156 created = true
125157
126- mspInst , err := msp .New (& msp. BCCSPNewOpts { NewBaseOpts : msp. NewBaseOpts { Version : msp . MSPv1_0 }} )
158+ mspInst , err := msp .New (newOpts )
127159 if err != nil {
128160 mspLogger .Fatalf ("Failed to initialize local MSP, received err %+v" , err )
129161 }
130162
131- lclMsp , err = cache .New (mspInst )
132- if err != nil {
133- mspLogger .Fatalf ("Failed to initialize local MSP, received err %+v" , err )
163+ switch mspType {
164+ case msp .ProviderTypeToString (msp .FABRIC ):
165+ lclMsp , err = cache .New (mspInst )
166+ if err != nil {
167+ mspLogger .Fatalf ("Failed to initialize local MSP, received err %+v" , err )
168+ }
169+ case msp .ProviderTypeToString (msp .IDEMIX ):
170+ lclMsp = mspInst
171+ default :
172+ panic ("msp type " + mspType + " unknown" )
134173 }
135174 localMsp = lclMsp
136175 }
0 commit comments