当我尝试在composer-playground中执行事务时,出现错误:预期为资源或概念,并且错误消息显示“期望资源或概念”。 交易名称为“ 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}聘用-聘用 * @交易 * /
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);
}
}
答案 0 :(得分:0)
在函数调用的第一行中,我将“ const”更改为“ let”。通过此修改,我能够在Hyperledger Composer操场上进行测试交易。您能检查一下是否适合您吗?
import "package:flutter/material.dart";
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Exploring Ui Widgets',
home: Scaffold(
body: getListView(),
),
));
}
Widget getListView() {
var listview = ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.accessible),
title: Text('Get Up!'),
subtitle: Text('Use your Legs!'),
trailing: Icon(Icons.accessible_forward),
onTap: () {
// I want to add a AlertDialog here!
},
),
ListTile(
leading: Icon(Icons.airline_seat_individual_suite),
title: Text('Wake Up!'),
subtitle: Text('Dont Sleep!'),
trailing: Icon(Icons.airline_seat_flat_angled),
)
],
);
return listview;
}