簡體   English   中英

獲取客戶端身份 fabric-contract-api-go

[英]Get client identity fabric-contract-api-go

fabric-contract-api-go中有一個獲取交易發起者身份的方法

func (ctx *TransactionContext) GetClientIdentity() cid.ClientIdentity

我們如何使用它來返回客戶端 ID,例如,在此合約中調用createhttps://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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM