Пример #1
0
//VerifyAttribute is used to verify if the transaction certificate has an attribute with name *attributeName* and value *attributeValue* which are the input parameters received by this function.
//Example:
//    containsAttr, error := stub.VerifyAttribute("position", "Software Engineer")
func (stub *ChaincodeStub) VerifyAttribute(attributeName string, attributeValue []byte) (bool, error) {
	attributesHandler, err := attr.NewAttributesHandlerImpl(stub)
	if err != nil {
		return false, err
	}
	return attributesHandler.VerifyAttribute(attributeName, attributeValue)
}
Пример #2
0
//VerifyAttributes does the same as VerifyAttribute but it checks for a list of attributes and their respective values instead of a single attribute/value pair
// Example:
//    containsAttrs, error:= stub.VerifyAttributes(&attr.Attribute{"position",  "Software Engineer"}, &attr.Attribute{"company", "ACompany"})
func (stub *ChaincodeStub) VerifyAttributes(attrs ...*attr.Attribute) (bool, error) {
	attributesHandler, err := attr.NewAttributesHandlerImpl(stub)
	if err != nil {
		return false, err
	}
	return attributesHandler.VerifyAttributes(attrs...)
}
Пример #3
0
//ReadCertAttribute is used to read an specific attribute from the transaction certificate, *attributeName* is passed as input parameter to this function.
// Example:
//  attrValue,error:=stub.ReadCertAttribute("position")
func (stub *ChaincodeStub) ReadCertAttribute(attributeName string) ([]byte, error) {
	attributesHandler, err := attr.NewAttributesHandlerImpl(stub)
	if err != nil {
		return nil, err
	}
	return attributesHandler.GetValue(attributeName)
}
Пример #4
0
func (t *Attributes2State) setStateToAttributes(stub shim.ChaincodeStubInterface, args []string) error {
	attrHandler, err := attr.NewAttributesHandlerImpl(stub)
	if err != nil {
		return err
	}
	for _, att := range args {
		fmt.Println("Writing attribute " + att)
		attVal, err := attrHandler.GetValue(att)
		if err != nil {
			return err
		}
		err = stub.PutState(att, attVal)
		if err != nil {
			return err
		}
	}
	return nil
}