我试图用cid库(https://github.com/hyperledger/fabric/tree/release-1.1/core/chaincode/lib/cid)检索链码中的属性值,但它返回一个空值 .

我修改了 fabcar sample以使用fabcar chaincode中的属性值进行实验 . 我的方法如下

cli 容器中没有

  • cid 库,因此我通过docker compose文件将整个结构代码库从主机映射到docker容器 .
    valumes: /home/asad/projects_fabric_1.2/src/github.com/hyperledger/fabric:/opt/gopath/src/github.com/hyperledger/fabric

现在我可以从 cid 库访问API .

2-我在我的配置文件中使用 ca.example.com (在fabcar示例中为CA)注册另一个用户( myuser ),如下所示:

id:
  name: myuser
  type: user
  affiliation: org1.department1
  maxenrollments: 0
  attributes:
   - name: hf.IntermediateCA
     value: false
   - name: hf.Registrar.Roles
     value: "peer,orderer,client,user"
   - name: hf.Registrar.DelegateRoles
     value: "peer,orderer,client,user"
   - name: hf.Registrar.Attributes
     value: "*"
   - name: hf.GenCRL
     value: false
   - name: hf.Revoker
     value: false
   - name: hf.AffiliationMgr
     value: false
   - name: 'full_name'
     value: "Jhon Doe"
   - name: 'department'
     value: "Computer Engineering"

我通过 fabric-ca-client 注册并注册 myuser ,并修改registerUser.js和invoke.js javascript文件使用 myuser .

现在我修改fabcar chaincode来检索和记录这些属性值 .

mspid, err := cid.GetMSPID(APIstub)

fmt.Printf("\nMSPID:\n %s \n\n", mspid)
fmt.Printf("\n\n\n")
if err != nil {
    fmt.Printf("\n%e\n\n", err)
}

attr1, ok, err := cid.GetAttributeValue(APIstub, "full_name")

if !ok {
    fmt.Printf("\nFull_Name not OK.\n")
}
fmt.Printf("\nfull_name:\n %s \n\n", attr1)
fmt.Printf("\n\n\n")
if err != nil {
    fmt.Printf("\n%e\n\n", err)
}

attr2, ok, err := cid.GetAttributeValue(APIstub, "department")

if !ok {
    fmt.Printf("\nDepartment not OK.\n")
}

fmt.Printf("\ndepartment:\n %s \n\n", attr2)
fmt.Printf("\n\n\n")
if err != nil {
    fmt.Printf("\n%e\n\n", err)
}

现在,当我通过 node invoke.js 运行调用链代码,并检查链代码容器的日志时,我得到以下输出 .

MSPID:
 Org1MSP 





Full_Name not OK.

full_name:






Department not OK.

department:

知道为什么我没有得到我的属性值...?