获取客户端身份结构合同-api-go

问题描述 投票:0回答:1

fabric-contract-api-go中有一种获取交易发起者身份的方法

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

在此合同create中调用例如https://github.com/hyperledger/fabric-contract-api-go/blob/master/tutorials/getting-started.md时,我们如何使用它返回客户ID”>

// ...
// ...

// 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
}

// ...
// ...

fabric-contract-api-go中有一种用于获取事务发起方的身份函数(ctx * TransactionContext)GetClientIdentity()cid.ClientIdentity的方法,当...时,我们如何使用它返回客户端ID,...

go hyperledger-fabric hyperledger-fabric-sdk-go
1个回答
0
投票
GetClientIdentity返回您此处定义的ClientIdentity类型的接口https://github.com/hyperledger/fabric-chaincode-go/blob/master/pkg/cid/interfaces.go这显示了您可以调用的功能,以检索有关事务提交者的信息(即客户身份)]
© www.soinside.com 2019 - 2024. All rights reserved.