gpt4 book ai didi

hyperledger-fabric - 如何从最新版本的 Hyperledger Fabric 中检索用户信息?

转载 作者:行者123 更新时间:2023-12-04 07:59:25 24 4
gpt4 key购买 nike

我是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com