![](/img/trans.png)
[英]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.