-1

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

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

例如create在本合同中调用时,我们如何使用它来返回客户端 ID 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
}

// ...
// ...
4

1 回答 1

1

GetClientIdentity返回您在此处定义的 ClientIdentity 类型的接口 https://github.com/hyperledger/fabric-chaincode-go/blob/master/pkg/cid/interfaces.go 这向您展示了您可以调用的函数以检索有关交易提交者(即客户身份)

于 2020-04-07T07:35:39.717 回答