本文整理匯總了Golang中github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStubInterface.VerifyAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Golang ChaincodeStubInterface.VerifyAttribute方法的具體用法?Golang ChaincodeStubInterface.VerifyAttribute怎麽用?Golang ChaincodeStubInterface.VerifyAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStubInterface
的用法示例。
在下文中一共展示了ChaincodeStubInterface.VerifyAttribute方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: delete
// delete Deletes an entity from the state, returning error if the entity was not found in the state.
func (t *Attributes2State) delete(stub shim.ChaincodeStubInterface, args []string) error {
if len(args) != 1 {
return errors.New("Incorrect number of arguments. Expecting only 1 (attributeName)")
}
attributeName := args[0]
fmt.Printf("Deleting attribute %v", attributeName)
valBytes, err := stub.GetState(attributeName)
if err != nil {
return err
}
if valBytes == nil {
return errors.New("Attribute '" + attributeName + "' not found.")
}
isOk, err := stub.VerifyAttribute(attributeName, valBytes)
if err != nil {
return err
}
if isOk {
// Delete the key from the state in ledger
err = stub.DelState(attributeName)
if err != nil {
return errors.New("Failed to delete state")
}
}
return nil
}
示例2: increment
//Invoke makes increment counter
func (t *AuthorizableCounterChaincode) increment(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {
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
}
示例3: 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.ChaincodeStubInterface, 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))
}