如何在链代码中获得用户的从属关系

问题描述 投票:1回答:2

有没有办法在链码中获得用户的联盟?我找不到用于在链代码中获得用户联系的API。

hyperledger-fabric
2个回答
0
投票

请查看core/chaincode/lib中提供的cid lib文档:

// Get the client ID object
id, err := cid.New(stub)
if err != nil {
   // Handle error
}
mspid, err := id.GetMSPID()
if err != nil {
   // Handle error
}
switch mspid {
   case "org1MSP":
      err = id.AssertAttributeValue("attr1", "true")
   case "org2MSP":
      err = id.AssertAttributeValue("attr2", "true")
   default:
      err = errors.New("Wrong MSP")
}

0
投票

联盟在证书主题内编码,在OU中。例如,org1.department 1用户的主题

'subject': 'CN=33932069-6fce-4b16-8072-6715d591f35b,OU=client+OU=org1+OU=department1,O=Org1'

所以,它可以很容易地从链码访问

invoker, err := identity.FromStub(c.Stub())
if err != nil {
    return nil, err
}

fmt.Printf(invoker.Cert.Subject.OrganizationalUnit)
© www.soinside.com 2019 - 2024. All rights reserved.