@@ -9,11 +9,11 @@ package channelconfig
9
9
import (
10
10
"fmt"
11
11
12
+ "github.com/golang/protobuf/proto"
12
13
"github.com/hyperledger/fabric/msp"
13
14
"github.com/hyperledger/fabric/msp/cache"
14
15
mspprotos "github.com/hyperledger/fabric/protos/msp"
15
-
16
- "github.com/golang/protobuf/proto"
16
+ "github.com/pkg/errors"
17
17
)
18
18
19
19
type pendingMSPConfig struct {
@@ -36,44 +36,54 @@ func NewMSPConfigHandler(mspVersion msp.MSPVersion) *MSPConfigHandler {
36
36
37
37
// ProposeValue called when an org defines an MSP
38
38
func (bh * MSPConfigHandler ) ProposeMSP (mspConfig * mspprotos.MSPConfig ) (msp.MSP , error ) {
39
- // check that the type for that MSP is supported
40
- if mspConfig . Type != int32 ( msp . FABRIC ) {
41
- return nil , fmt . Errorf ( "Setup error: unsupported msp type %d" , mspConfig . Type )
42
- }
43
-
44
- // create the msp instance
45
- mspInst , err := msp .New (& msp.BCCSPNewOpts {NewBaseOpts : msp.NewBaseOpts {Version : bh .version }})
46
- if err != nil {
47
- return nil , fmt . Errorf ( "Creating the MSP manager failed, err %s" , err )
48
- }
39
+ var theMsp msp. MSP
40
+ var err error
41
+
42
+ switch mspConfig . Type {
43
+ case int32 ( msp . FABRIC ):
44
+ // create the bccsp msp instance
45
+ mspInst , err := msp .New (& msp.BCCSPNewOpts {NewBaseOpts : msp.NewBaseOpts {Version : bh .version }})
46
+ if err != nil {
47
+ return nil , errors . WithMessage ( err , "creating the MSP manager failed" )
48
+ }
49
49
50
- casheMSP , err := cache .New (mspInst )
51
- if err != nil {
52
- return nil , fmt .Errorf ("Creating the MSP manager failed, err %s" , err )
50
+ // add a cache layer on top
51
+ theMsp , err = cache .New (mspInst )
52
+ if err != nil {
53
+ return nil , errors .WithMessage (err , "creating the MSP cache failed" )
54
+ }
55
+ case int32 (msp .IDEMIX ):
56
+ // create the idemix msp instance
57
+ theMsp , err = msp .New (& msp.IdemixNewOpts {msp.NewBaseOpts {Version : bh .version }})
58
+ if err != nil {
59
+ return nil , errors .WithMessage (err , "creating the MSP manager failed" )
60
+ }
61
+ default :
62
+ return nil , errors .New (fmt .Sprintf ("Setup error: unsupported msp type %d" , mspConfig .Type ))
53
63
}
54
64
55
65
// set it up
56
- err = casheMSP .Setup (mspConfig )
66
+ err = theMsp .Setup (mspConfig )
57
67
if err != nil {
58
- return nil , fmt . Errorf ( "Setting up the MSP manager failed, err %s" , err )
68
+ return nil , errors . WithMessage ( err , "setting up the MSP manager failed" )
59
69
}
60
70
61
71
// add the MSP to the map of pending MSPs
62
- mspID , _ := casheMSP .GetIdentifier ()
72
+ mspID , _ := theMsp .GetIdentifier ()
63
73
64
74
existingPendingMSPConfig , ok := bh .idMap [mspID ]
65
75
if ok && ! proto .Equal (existingPendingMSPConfig .mspConfig , mspConfig ) {
66
- return nil , fmt .Errorf ("Attempted to define two different versions of MSP: %s" , mspID )
76
+ return nil , errors . New ( fmt .Sprintf ("Attempted to define two different versions of MSP: %s" , mspID ) )
67
77
}
68
78
69
79
if ! ok {
70
80
bh .idMap [mspID ] = & pendingMSPConfig {
71
81
mspConfig : mspConfig ,
72
- msp : casheMSP ,
82
+ msp : theMsp ,
73
83
}
74
84
}
75
85
76
- return casheMSP , nil
86
+ return theMsp , nil
77
87
}
78
88
79
89
func (bh * MSPConfigHandler ) CreateMSPManager () (msp.MSPManager , error ) {
0 commit comments