繁体   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