将资产添加到hyperledger-composer中的参与者:错误消息“模型违反...”

时间:2018-07-27 14:15:01

标签: hyperledger-composer

在我的hyperledger-composer应用程序中,我有顾问和技能。此外,我有一个名为“ UpdateSkillsOfConsultant”的事务,可以将这项技能添加到顾问中。

但是,提交交易会导致以下错误消息:

enter image description here

我不知道该如何处理此错误消息。

我创建了一个最小的示例,可以将其复制并粘贴到作曲家-playground中。

这是要复制到model.cto文件中的东西:

namespace org.comp.myapp



abstract participant User identified by id {
  o String id
  o String firstName
  o String lastName
  o String email
  o String password
}

participant Consultant extends User {

  --> Skill[] skills optional

}

asset Skill identified by id {
  o String id
  o String name
  o Proficiency proficiency
}

enum Proficiency {
  o Beginner
  o Intermediate
  o Advanced
}


transaction UpdateSkillsOfConsultant {
  --> Consultant consultant
  --> Skill[] newSkills
}


event ConsultantUpdated {
  o Consultant consultantOld
  o Consultant consultantNew
}

这是script.js文件的内容:

 'use strict';



    /**
 * transaction UpdateSkillsOfConsultant
 * @param {org.comp.myapp.UpdateSkillsOfConsultant} transaction
 * @transaction
 */
async function updateSkillsOfConsultant(transaction) {

    // Save the old version of the consultant:
    const consultantOld = transaction.consultant;

    // Update the consultant with the new skills:
    const existingSkills = consultantOld.skills;
    for (newSkill in transaction.newSkills) {

            if (!transaction.consultant.skills) {
                transaction.consultant.skills = [newSkill];
            }
            else {
                transaction.consultant.skills = transaction.consultant.skills.concat(newSkill);
            }  

    } 

    // Get the participant registry containing the consultants:
    const participantRegistry = await getParticipantRegistry('org.comp.myapp.Consultant');

    // Update the consultant in the participant registry:
    await participantRegistry.update(transaction.consultant);

    // Emit an event for the modified consultant:
    let event = getFactory().newEvent('org.comp.myapp', 'ConsultantUpdated');
    event.consultantOld = consultantOld;
    event.consultantNew = transaction.consultant;
    emit(event);


}




//helper function:

function findSkill(array, name) {
    if(array) {
        for (let i=0; i<array.length; i++) {
            if (array[i].name == name) {
                return array[i];
            }
        }
    }
    return null;
}

要重现该错误,只需将所有内容复制并粘贴到作曲家游乐场中,创建顾问,创建技能,然后尝试提交事务“ org.comp.myapp.UpdateSkillsOfConsultant”。

1 个答案:

答案 0 :(得分:1)

这是一个JavaScript问题。线

for sentence in sent_list: new_sentence = sent + '. ' print(new_sentence.capitalize())

如果仅将1值传递给数组,

将返回数组的键(将为0,1,2 ...),那么它将返回值 for (newSkill in transaction.newSkills) { ,这是您看到的错误。将行更改为

0

这将解决您的问题。