This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 2
/
factory.go
67 lines (56 loc) · 1.46 KB
/
factory.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msp
import (
"github.com/pkg/errors"
)
type MSPVersion int
const (
MSPv1_0 = iota
MSPv1_1
)
// NewOpts represent
type NewOpts interface {
// GetVersion returns the MSP's version to be instantiated
GetVersion() MSPVersion
}
// NewBaseOpts is the default base type for all MSP instantiation Opts
type NewBaseOpts struct {
Version MSPVersion
}
func (o *NewBaseOpts) GetVersion() MSPVersion {
return o.Version
}
// BCCSPNewOpts contains the options to instantiate a new BCCSP-based (X509) MSP
type BCCSPNewOpts struct {
NewBaseOpts
}
// IdemixNewOpts contains the options to instantiate a new Idemix-based MSP
type IdemixNewOpts struct {
NewBaseOpts
}
// New create a new MSP instance depending on the passed Opts
func New(opts NewOpts) (MSP, error) {
switch opts.(type) {
case *BCCSPNewOpts:
switch opts.GetVersion() {
case MSPv1_0:
return newBccspMsp(MSPv1_0)
case MSPv1_1:
return newBccspMsp(MSPv1_1)
default:
return nil, errors.Errorf("Invalid *BCCSPNewOpts. Version not recognized [%v]", opts.GetVersion())
}
case *IdemixNewOpts:
switch opts.GetVersion() {
case MSPv1_1:
return newIdemixMsp()
default:
return nil, errors.Errorf("Invalid *IdemixNewOpts. Version not recognized [%v]", opts.GetVersion())
}
default:
return nil, errors.Errorf("Invalid msp.NewOpts instance. It must be either *BCCSPNewOpts or *IdemixNewOpts. It was [%v]", opts)
}
}