[英]What is the difference between fabric-chaincode-go and fabric-contract-api-go?
[英]Get client identity fabric-contract-api-go
在fabric-contract-api-go中有一个获取交易发起者身份的方法
func (ctx *TransactionContext) GetClientIdentity() cid.ClientIdentity
我们如何使用它来返回客户端 ID,例如,在此合约中调用create
时https://github.com/hyperledger/fabric-contract-api-go/blob/master/tutorials/getting-started.md
// ...
// ...
// Create adds a new key with value to the world state
func (sc *SimpleContract) Create(ctx contractapi.TransactionContextInterface, key string, value string) error {
existing, err := ctx.GetStub().GetState(key)
if err != nil {
return errors.New("Unable to interact with world state")
}
if existing != nil {
return fmt.Errorf("Cannot create world state pair with key %s. Already exists", key)
}
err = ctx.GetStub().PutState(key, []byte(value))
if err != nil {
return errors.New("Unable to interact with world state")
}
return nil
}
// ...
// ...
GetClientIdentity
为您返回此处定义的 ClientIdentity 类型的接口https://github.com/hyperledger/fabric-chaincode-go/blob/master/pkg/cid/interfaces.go这显示了您可以调用的函数以检索有关信息交易提交者(即客户身份)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.