當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ChaincodeStub.VerifyAttribute方法代碼示例

本文整理匯總了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

}
開發者ID:C0rWin,項目名稱:fabric,代碼行數:25,代碼來源:authorizable_counter.go

示例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))
}
開發者ID:C0rWin,項目名稱:fabric,代碼行數:7,代碼來源:cert_handler.go


注:本文中的github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStub.VerifyAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。