1 Star 0 Fork 0

陈文甲/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
factory.go 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
/*
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
MSPv1_3
)
// 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)
case MSPv1_3:
return newBccspMsp(MSPv1_3)
default:
return nil, errors.Errorf("Invalid *BCCSPNewOpts. Version not recognized [%v]", opts.GetVersion())
}
case *IdemixNewOpts:
switch opts.GetVersion() {
case MSPv1_3:
return newIdemixMsp(MSPv1_3)
case MSPv1_1:
return newIdemixMsp(MSPv1_1)
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)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/venjia/fabric.git
git@gitee.com:venjia/fabric.git
venjia
fabric
fabric
v1.4.0-rc1

搜索帮助