There's a method in fabric-contract-api-go for getting transaction initiator's Identity
func (ctx *TransactionContext) GetClientIdentity() cid.ClientIdentity
How'd we use it to return client ID when, eg , create
is invoked in this contract 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
returns you an interface of type ClientIdentity defined here https://github.com/hyperledger/fabric-chaincode-go/blob/master/pkg/cid/interfaces.go This shows you the functions you can then invoke to retrieve information about the transaction submitter (ie the client identity)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.