1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | func GetCertAttribute(stub shim.ChaincodeStubInterface, attributeName string) (string, error) { fmt.Println("Entering GetCertAttribute") attr, err := stub.ReadCertAttribute(attributeName) if err != nil { return "", errors.New("Couldn't get attribute " + attributeName + ". Error: " + err.Error()) } attrString := string(attr) return attrString, nil } func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) { if function == "CreateLoanApplication" { username, _ := GetCertAttribute(stub, "username") role, _ := GetCertAttribute(stub, "role") if role == "Bank_Home_Loan_Admin" { return CreateLoanApplication(stub, args) } else { return nil, errors.New(username + " with role " + role + " does not have access to create a loan application") } } return nil, nil } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |