Ошибка: ожидался ресурс или концепция в программе для составления гипертелгеров - PullRequest
1 голос
/ 06 мая 2019

Когда я пытаюсь выполнить транзакцию на площадке для композиторов, я получаю сообщение об ошибке: «Ожидается ресурс или концепция», а в сообщении об ошибке говорится «Ожидается ресурс или концепция».имя транзакции: «HireEmployee».

/ * Вот мой файл .cto: * /

namespace org.example.basic


/** 
*Asset Job Defenition
*/

enum JobState {
o OPEN
o ON_LIVE
o HIRED
}

concept JobDescription {
o String jobTitle
o String jobdescription
o String skill
o String Duration
}

asset Job identified by jobId {
o String jobId
--> Employer employer
--> Member hiredemployee optional
o Double budget
o JobState state
o JobDescription description
o Bid[] offers optional
}

/**
*Asset Forum Defenition
*/


asset Forum identified by forumId {
  o String forumId
  -->Member owner
  o String question
  o Solution[] solutions optional
}

/**
* Participants of the network
*/


abstract participant User identified by userId {
  o String userId
  o String firstName
  o String lastName
}

participant Member extends User {
 o Double expPoint
 o Double credit
}

participant Employer extends User {
  o Double credit
}

/**
*Transactions
*/

transaction Bid {
  o Double bidPrice
  -->Job job
  -->Member member
}


transaction HireEmployee {
  -->Job job
}

transaction Solution {
  o String answer
  -->Forum forum
  -->Member member

}

/ ** файл цепочки кода * Наймите сотрудника * @param {org.example.basic.HireEmployee} найм - найм * @transaction * /

async function hireEmployee(hire) {
    const job = hire.job;
    if (job.state !== 'OPEN') {
        throw new Error('This Job is Closed and Someone is Already Hired');
    }

    job.state = 'ON_LIVE';  
    let lowestOffer = null;
    let employee = null;
    let employer =null;

    if (job.offers && job.offers.length > 0) {
        // sort the bids by bidPrice
        job.offers.sort(function(a, b) {
            return (a.bidPrice - b.bidPrice);
        });
        lowestOffer = job.offers[0];
        if (lowestOffer.bidPrice >= 5 ) {
            // mark the job as Hired
            job.state = 'HIRED';
            let employer = job.employer;
            let employee = lowestOffer.member;

            console.log('#### employer balance before: ' + employer.credit);
            employer.credit -= lowestOffer.bidPrice;
            console.log('#### employer balance after: ' + employer.credit);
            // update the balance of the buyer
            console.log('#### Employee balance before: ' + employee.credit);
            employee.credit += lowestOffer.bidPrice;
            console.log('#### buyer balance after: ' + employee.credit);
            // mark the hire employee
            job.hiredemployee = employee;

            job.offers = null;
        }
    }

     // save the bid
    const jobRegistry = await getAssetRegistry('org.example.basic.Job');
    await jobRegistry.update(job);

    if (job.state === 'HIRED') {
        // save the buyer
        const memberRegistry = await getParticipantRegistry('org.example.basic.Member');
        await memberRegistry.update(employee);

        const userRegistry = await getParticipantRegistry('org.example.basic.Employer');
        await userRegistry.update(employer);
    }


}

1 Ответ

0 голосов
/ 12 мая 2019

В первой строке вызова функции я изменил «const» на «let».С этой модификацией мне удалось провести тестовую транзакцию на площадке Hyperledger Composer.Не могли бы вы проверить, работает ли это для вас?

/** 
* Hire an Employee 
* @param {org.example.basic.HireEmployee} hire - the hire 
* @transaction 
*/

async function hireEmployee(hire) {
    let job = hire.job;
    if (job.state !== 'OPEN') {
        throw new Error('This Job is Closed and Someone is Already Hired');
    }

    job.state = 'ON_LIVE';  
    let lowestOffer = null;
    let employee = null;
    let employer =null;

    if (job.offers && job.offers.length > 0) {
        // sort the bids by bidPrice
        job.offers.sort(function(a, b) {
            return (a.bidPrice - b.bidPrice);
        });
        lowestOffer = job.offers[0];
        if (lowestOffer.bidPrice >= 5 ) {
            // mark the job as Hired
            job.state = 'HIRED';
            let employer = job.employer;
            let employee = lowestOffer.member;

            console.log('#### employer balance before: ' + employer.credit);
            employer.credit -= lowestOffer.bidPrice;
            console.log('#### employer balance after: ' + employer.credit);
            // update the balance of the buyer
            console.log('#### Employee balance before: ' + employee.credit);
            employee.credit += lowestOffer.bidPrice;
            console.log('#### buyer balance after: ' + employee.credit);
            // mark the hire employee
            job.hiredemployee = employee;

            job.offers = null;
        }
    }

     // save the bid
    const jobRegistry = await getAssetRegistry('org.example.basic.Job');
    await jobRegistry.update(job);

    if (job.state === 'HIRED') {
        // save the buyer
        const memberRegistry = await getParticipantRegistry('org.example.basic.Member');
        await memberRegistry.update(employee);

        const userRegistry = await getParticipantRegistry('org.example.basic.Employer');
        await userRegistry.update(employer);
    }


}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...