作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Hyperledger Fabric 的新手。在当前版本的 Hyperledger Fabric 中,在 chaincode.go 中我找不到名为 ReadCertAttributes 的函数。有没有办法获取属性?
最佳答案
从 Hypeledger Fabric 1.0.0 开始,您可以使用 GetCreator
ChaincodeStubInterface
的方法获取客户证书,例如:
// GetCreator returns `SignatureHeader.Creator` (e.g. an identity)
// of the `SignedProposal`. This is the identity of the agent (or user)
// submitting the transaction.
GetCreator() ([]byte, error)
例如你可以做类似的事情:
func (*smartContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
fmt.Println("Invoke")
// GetCreator returns marshaled serialized identity of the client
serializedID, _ := stub.GetCreator()
sId := &msp.SerializedIdentity{}
err := proto.Unmarshal(serializedID, sId)
if err != nil {
return shim.Error(fmt.Sprintf("Could not deserialize a SerializedIdentity, err %s", err))
}
bl, _ := pem.Decode(sId.IdBytes)
if bl == nil {
return shim.Error(fmt.Sprintf("Failed to decode PEM structure"))
}
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
return shim.Error(fmt.Sprintf("Unable to parse certificate %s", err))
}
// Do whatever you need with certificate
return shim.Success(nil)
}
关于hyperledger-fabric - 如何从最新版本的 Hyperledger Fabric 中检索用户信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45786023/
我是一名优秀的程序员,十分优秀!