错误:ID为'Participant:xxxt'的集合中ID为'undefined'的对象不存在

问题描述 投票:0回答:1

我在hyperledger网站上的操场上执行了这些代码,错误显示在此处:错误:ID为'参与者:xxxt'的集合中ID为'undefined'的对象不存在。

/**
 * Track the trade of a commodity from one trader to another
 * @param {org.fordham.education.ModifyTranscript} modify - the trade to be processed
 * @transaction
 */

async function modifyTranscript(modify){
    const Assetregistry=await getAssetRegistry('org.fordham.education.Transcript');
    // const participantRegistryC = await getParticipantRegistry('org.fordham.education.Company');
    // const participantRegistrySC = await getParticipantRegistry('org.fordham.education.School'); // eslint-disable-line no-undef
    const factory=getFactory();
    const newasset=factory.newResource('org.fordham.education','Transcript',modify.mId);
    //modify aspects
    newasset.gpa=modify.gpa;
    newasset.remarks=modify.remarks;
    newasset.studentName=modify.studentName;
    newasset.studentId=modify.studentId;
    newasset.GraduationDate=modify.GraduationDate;
    newasset.issueDate=modify.issueDate;
    //participants
    const SchoolRef=factory.newRelationship('org.fordham.education','School',getCurrentParticipant().getIdentifier());//add school
    newasset.school=SchoolRef; 
  	const participantRegistryS = await getParticipantRegistry('org.fordham.education.Student');//get student participant
    const toStudent = await participantRegistryS.get(modify.student);
    const StudentRef=factory.newRelationship('org.fordham.education','Student',toStudent.getIdentifier());
    newasset.student=StudentRef; 
  	//const CompanyRef=factory.newRelationship('org.fordham.education','Company',getCurrentParticipant().getIdentifier());
    //newasset.viewedBy=CompanyRef; 

  await Assetregistry.add(newasset);
  

}

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Definition of a Bond, based on the FpML schema:
 * http://www.fpml.org/spec/fpml-5-3-2-wd-2/html/reporting/schemaDocumentation/schemas/fpml-asset-5-3_xsd/elements/bond.html
 *
 */
namespace org.fordham.education

participant School identified by Schoolid {
  o String Schoolid
  o String name
  o String level //undergraduate or graduate or college 
}

participant Company identified by Companyid {
  o String Companyid
  o String name
  o String identity //company type finance/consultant/tech can use enum
}

participant Student identified by sId{
  o String sId
  o String studentName
  o String major
  o String nationality
  o String gender
  o String classOfYear
}


asset Transcript identified by tId{
  o String tId
  o Double gpa default =0.0
  o String remarks 
  o String studentName
  o String studentId
  o DateTime GraduationDate
  o DateTime issueDate
  --> School school
  --> Student student
  --> Company viewedBy optional
}
  
transaction ModifyTranscript{
  --> School school 
  o String mId //tid is the identifier in the asset, we need to in clude this in the transaction 
  o Double gpa default =0.0
  o String remarks 
  o String studentName
  o String studentId
  o DateTime GraduationDate
  o DateTime issueDate
}

transaction ModifyByStudent{
  //student add the company to the array
  o String addCompany
  o String removeCompany
  --> Student Student
  --> Company newViewBy optional
}




//logic file todo list
// get assetRegistry
//getFactory
//newResource(namespace org.fordham.education,TranscriptViewBy,tVid)
//
//.status=.status
//.ReviewedCompany=.ReviewedCompany
//.add(TranscriptViewBy)  add asset
//
hyperledger-composer
1个回答
0
投票

根据我的理解,你需要使用Transcript交易新的ModifyTranscript资产。所以在你的代码中,你需要在student事务上添加一个ModifyTranscript关系。

1. cto文件更改:

transaction ModifyTranscript
{
  --> School school
   o String mId
   o Double gpa defaul=0.0 
   o String remarks
   o String studentName
   o String studentId
   o DateTime GraduationDate
   o DateTime issueDate
  --> Student student
}

2. logic.js更改:

 async function modifyTranscript(modify){

    const Assetregistry=await getAssetRegistry('org.fordham.education.Transcript');
    // const participantRegistryC = await getParticipantRegistry('org.fordham.education.Company');
    // const participantRegistrySC = await getParticipantRegistry('org.fordham.education.School'); // eslint-disable-line no-undef
    const factory=getFactory();
    const newasset= factory.newResource('org.fordham.education','Transcript',modify.mId);
    //modify aspects
    newasset.gpa=modify.gpa;
    newasset.remarks=modify.remarks;
    newasset.studentName=modify.studentName;
    newasset.studentId=modify.studentId;
    newasset.GraduationDate=modify.GraduationDate;
    newasset.issueDate=modify.issueDate;
    //participants
    const SchoolRef = factory.newRelationship('org.fordham.education','School',getCurrentParticipant().getIdentifier());//add school
    newasset.school = SchoolRef; 


    const StudentRef=  factory.newRelationship('org.fordham.education','Student',(modify.student).getIdentifier());
    newasset.student=StudentRef;

    await Assetregistry.add(newasset); 
}

我希望它能解决你的错误:)

© www.soinside.com 2019 - 2024. All rights reserved.