1 Star 0 Fork 0

陈文甲 / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
helper.go 2.93 KB
一键复制 编辑 原始数据 按行查看 历史
Jason Yellick 提交于 2019-02-01 14:33 . FAB-14037 Remove unreachable code
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package test
import (
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/genesis"
"github.com/hyperledger/fabric/common/tools/configtxgen/configtxgentest"
"github.com/hyperledger/fabric/common/tools/configtxgen/encoder"
genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig"
"github.com/hyperledger/fabric/core/ledger/util"
cb "github.com/hyperledger/fabric/protos/common"
mspproto "github.com/hyperledger/fabric/protos/msp"
"github.com/hyperledger/fabric/protos/peer"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
)
var logger = flogging.MustGetLogger("common.configtx.test")
// MakeGenesisBlock creates a genesis block using the test templates for the given chainID
func MakeGenesisBlock(chainID string) (*cb.Block, error) {
profile := configtxgentest.Load(genesisconfig.SampleDevModeSoloProfile)
channelGroup, err := encoder.NewChannelGroup(profile)
if err != nil {
logger.Panicf("Error creating channel config: %s", err)
}
gb := genesis.NewFactoryImpl(channelGroup).Block(chainID)
if gb == nil {
return gb, nil
}
txsFilter := util.NewTxValidationFlagsSetValue(len(gb.Data.Data), peer.TxValidationCode_VALID)
gb.Metadata.Metadata[cb.BlockMetadataIndex_TRANSACTIONS_FILTER] = txsFilter
return gb, nil
}
// MakeGenesisBlockWithMSPs creates a genesis block using the MSPs provided for the given chainID
func MakeGenesisBlockFromMSPs(chainID string, appMSPConf, ordererMSPConf *mspproto.MSPConfig, appOrgID, ordererOrgID string) (*cb.Block, error) {
profile := configtxgentest.Load(genesisconfig.SampleDevModeSoloProfile)
profile.Orderer.Organizations = nil
channelGroup, err := encoder.NewChannelGroup(profile)
if err != nil {
logger.Panicf("Error creating channel config: %s", err)
}
ordererOrg := cb.NewConfigGroup()
ordererOrg.ModPolicy = channelconfig.AdminsPolicyKey
ordererOrg.Values[channelconfig.MSPKey] = &cb.ConfigValue{
Value: utils.MarshalOrPanic(channelconfig.MSPValue(ordererMSPConf).Value()),
ModPolicy: channelconfig.AdminsPolicyKey,
}
applicationOrg := cb.NewConfigGroup()
applicationOrg.ModPolicy = channelconfig.AdminsPolicyKey
applicationOrg.Values[channelconfig.MSPKey] = &cb.ConfigValue{
Value: utils.MarshalOrPanic(channelconfig.MSPValue(appMSPConf).Value()),
ModPolicy: channelconfig.AdminsPolicyKey,
}
applicationOrg.Values[channelconfig.AnchorPeersKey] = &cb.ConfigValue{
Value: utils.MarshalOrPanic(channelconfig.AnchorPeersValue([]*pb.AnchorPeer{}).Value()),
ModPolicy: channelconfig.AdminsPolicyKey,
}
channelGroup.Groups[channelconfig.OrdererGroupKey].Groups[ordererOrgID] = ordererOrg
channelGroup.Groups[channelconfig.ApplicationGroupKey].Groups[appOrgID] = applicationOrg
return genesis.NewFactoryImpl(channelGroup).Block(chainID), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/venjia/fabric.git
git@gitee.com:venjia/fabric.git
venjia
fabric
fabric
v1.4.5

搜索帮助

344bd9b3 5694891 D2dac590 5694891