本文整理匯總了Golang中github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStub.VerifyAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Golang ChaincodeStub.VerifyAttribute方法的具體用法?Golang ChaincodeStub.VerifyAttribute怎麽用?Golang ChaincodeStub.VerifyAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStub
的用法示例。
在下文中一共展示了ChaincodeStub.VerifyAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Invoke
//Invoke Transaction makes increment counter
func (t *AuthorizableCounterChaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
if function != "increment" {
return nil, errors.New("Invalid invoke function name. Expecting \"increment\"")
}
val, err := stub.ReadCertAttribute("position")
fmt.Printf("Position => %v error %v \n", string(val), err)
isOk, _ := stub.VerifyAttribute("position", []byte("Software Engineer")) // Here the ABAC API is called to verify the attribute, just if the value is verified the counter will be incremented.
if isOk {
counter, err := stub.GetState("counter")
if err != nil {
return nil, err
}
var cInt int
cInt, err = strconv.Atoi(string(counter))
if err != nil {
return nil, err
}
cInt = cInt + 1
counter = []byte(strconv.Itoa(cInt))
stub.PutState("counter", counter)
}
return nil, nil
}
示例2: isAuthorized
// isAuthorized checks if the transaction invoker has the appropriate role
// stub: chaincodestub
// requiredRole: required role; this function will return true if invoker has this role
func (t *certHandler) isAuthorized(stub *shim.ChaincodeStub, requiredRole string) (bool, error) {
//read transaction invoker's role, and verify that is the same as the required role passed in
return stub.VerifyAttribute(role, []byte(requiredRole))
}