如何在Fabric SDK Go中添加集合配置?
我正在使用Fabric SDK Go将私有数据添加到Hyperledger中,但在调用数据时出错 实例化链码 collections\u config.json 援引 错误 因此,它表示在链码实例化期间未定义集合配置。但是,我不知道如何在链码实例化请求中添加集合配置如何在Fabric SDK Go中添加集合配置?,go,hyperledger-fabric,blockchain,hyperledger,Go,Hyperledger Fabric,Blockchain,Hyperledger,我正在使用Fabric SDK Go将私有数据添加到Hyperledger中,但在调用数据时出错 实例化链码 collections\u config.json 援引 错误 因此,它表示在链码实例化期间未定义集合配置。但是,我不知道如何在链码实例化请求中添加集合配置 请给我建议解决方案。您应该能够将其作为参数提供给实例化的ECCLESQUEST结构-特别是CollConfig-您可以在Go docs->中查看结构,这里描述了CollectionConfig类型->我能够以以下方式创建CollCo
请给我建议解决方案。您应该能够将其作为参数提供给实例化的ECCLESQUEST结构-特别是CollConfig-您可以在Go docs->中查看结构,这里描述了CollectionConfig类型->我能够以以下方式创建CollConfig请求,并且能够添加集合配置进入我的链码实例化 我的解决方案 配置1 配置2 实例化链码 CollConfig创建请求方法
谢谢,是的,我试过了CollConfig sturct请求,成功了
ccPolicy, err := cauthdsl.FromString("AND ('Org1MSP.member','Org2MSP.member')")
resMgmt.InstantiateCC(
setup.Org.ChannelID,
resmgmt.InstantiateCCRequest{
Name: chaincodeId,
Path: setup.Org.ChaincodePath,
Version: chaincodeVersion,
Args: [][]byte{[]byte("init")},
Policy: ccPolicy,
},resmgmt.WithRetry(retry.DefaultResMgmtOpts))
[
{
"name": "collectionMedium",
"policy": "AND ('Org1MSP.member', 'Org2MSP.member')",
"requiredPeerCount": 0,
"maxPeerCount": 3,
"blockToLive":1000000
},
{
"name": "collectionPrivate",
"policy": "OR('Org2MSP.member')",
"requiredPeerCount": 0,
"maxPeerCount": 3,
"blockToLive":5
}
]
product := &model.Product{id, name, color, length, width}
productBytes, err1 := json.Marshal(product)
if err1 != nil {
return shim.Error(err1.Error())
}
err2 := stub.PutPrivateData("collectionMedium", id, productBytes)
if err2 != nil {
return shim.Error(err2.Error())
}
Chaincode status Code: (500) UNKNOWN. Description: PUT_STATE failed: collection config not defined for chaincode [CC_ORG_V00], pass the collection configuration upon chaincode definition/instantiation
var collCfg1RequiredPeerCount, collCfg1MaximumPeerCount int32
var collCfg1BlockToLive uint64
collCfg1Name := "collectionMedium"
collCfg1BlockToLive = 1000
collCfg1RequiredPeerCount = 0
collCfg1MaximumPeerCount = 3
collCfg1Policy := "OR('Org1MSP.member','Org2MSP.member')"
collCfg1, err := newCollectionConfig(collCfg1Name,collCfg1Policy, collCfg1RequiredPeerCount,collCfg1MaximumPeerCount,collCfg1BlockToLive)
if err != nil {
return errors.WithMessage(err, "failed to create collection config 1")
}
var collCfg2RequiredPeerCount, collCfg2MaximumPeerCount int32
var collCfg2BlockToLive uint64
collCfg2Name := "collectionPrivate"
collCfg2BlockToLive = 100
collCfg2RequiredPeerCount = 0
collCfg2MaximumPeerCount = 3
collCfg2Policy := "OR('Org2MSP.member')"
collCfg2, err := newCollectionConfig(collCfg2Name,collCfg2Policy, collCfg2RequiredPeerCount,collCfg2MaximumPeerCount,collCfg2BlockToLive)
if err != nil {
return errors.WithMessage(err, "failed to create collection config 1")
}
cfg := []*cb.CollectionConfig{collCfg1,collCfg2}
resp, err := resMgmt.InstantiateCC(
setup.Org.ChannelID,
resmgmt.InstantiateCCRequest{
Name: chaincodeId,
Path: setup.Org.ChaincodePath,
Version: chaincodeVersion,
Args: [][]byte{[]byte("init")},
Policy: ccPolicy,
CollConfig: cfg,
},resmgmt.WithRetry(retry.DefaultResMgmtOpts))
func newCollectionConfig(colName, policy string, reqPeerCount, maxPeerCount int32,
blockToLive uint64) (*cb.CollectionConfig, error) {
p, err := cauthdsl.FromString(policy)
if err != nil {
return nil, err
}
cpc := &cb.CollectionPolicyConfig{
Payload: &cb.CollectionPolicyConfig_SignaturePolicy{
SignaturePolicy: p,
},
}
return &cb.CollectionConfig{
Payload: &cb.CollectionConfig_StaticCollectionConfig{
StaticCollectionConfig: &cb.StaticCollectionConfig{
Name: colName,
MemberOrgsPolicy: cpc,
RequiredPeerCount: reqPeerCount,
MaximumPeerCount: maxPeerCount,
BlockToLive: blockToLive,
},
},
}, nil }