在结构合约api go中有一个方法用于获取事务发起方的Identity
func (ctx *TransactionContext) GetClientIdentity() cid.ClientIdentity
当,例如,create
在该合同中被调用时,我们如何使用它来返回客户端IDhttps://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这向您展示了您可以调用的功能,以检索有关事务提交者的信息(即客户端身份(