Hyperledger 链码不获取当前用户元数据

Hyperledger chaincode does not get current user metadata

目前我正在使用 Hyperledger 链代码并尝试至少获取有关 invokes/queries 链代码的当前用户的任何信息。出于某种原因,链码示例 asset_management.go 导致错误 "ERRO 031 Got error: Invalid admin certificate. Empty." 我将 security.enabled 和 security.privacy 设置为 true 并且将会员服务设置为 运行。我已经注册 "admin".

这是代码中发生的行

// Set the admin
// The metadata will contain the certificate of the administrator
adminCert, err := stub.GetCallerMetadata()
if err != nil {
    myLogger.Debug("Failed getting metadata")
    return nil, errors.New("Failed getting metadata.")
}
if len(adminCert) == 0 {
    myLogger.Debug("Invalid admin certificate. Empty.")
    return nil, errors.New("Invalid admin certificate. Empty.")
}

您是否知道如何为 stub.GetCallerMetadata() 制作链代码 return 任何数据?

"Metadata" 应在部署命令中提供,例如 "deploy" for asset_management_with_roles:

curl -XPOST -d ‘{“jsonrpc": "2.0", "method": "deploy", "params": {"type": 1,"chaincodeID": {"path": "github.com/hyperledger/fabric/examples/chaincode/go/asset_management_with_roles","language": "GOLANG"}, "ctorMsg": { "args": ["init"] }, "metadata":[97, 115, 115, 105, 103, 110, 101, 114] ,"secureContext": "assigner"} ,"id": 0}' http://localhost:7050/chaincode

在此命令中 "metadata" 包含 utf-8 编码的字符串“assigner”。该字符串将保存在分类帐中,只有具有此类角色的用户才能在智能合约中执行“分配”功能。

"asset_management" 示例要求您在元数据字段中提供证书。为了获得证书,您可以使用相关问题中描述的步骤 9:How is running the asset_management.go different from running a simple chaincode like chaincode_example02.go