我是hyperledger的初学者。我的model.cto
文件有两个交易处理器功能,一个用于将汽车从制造商转移到展厅,另一个用于将汽车从展厅转移到车主。 model.cto
文件如下,
namespace org.manufacturer.network
asset Car identified by carID {
o String carID
o String name
o String chasisNumber
--> Showroom showroom
--> Owner owner
}
participant Showroom identified by showroomID {
o String showroomID
o String name
}
participant Owner identified by ownerID {
o String ownerID
o String firstName
o String lastName
}
transaction Allocate {
--> Car car
--> Showroom newShowroom
}
transaction Purchase {
--> Showroom showroom
--> Owner newOwner
}
所以,我想在我的script.js
文件中添加两个函数,以便我可以执行我的事务。我的script.js
文件如下
/**
* New script file
* @param {org.manufacturer.network.Allocate} allocate - allocating the car from manufacturer to showroom
* @param {org.manufacturer.network.Purchase} purchase - purchase the car by owner from showroom
* @transaction
*/
async function transferCar(allocate){
allocate.car.showroom = allocate.newShowroom;
let assetRegistry = await getAssetRegistry('org.manufacturer.network.Car');
await assetRegistry.update(allocate.car);
}
async function purchaseCar(purchase){
purchase.car.owner = purchase.newOwner;
let assetRegistry = await getAssetRegistry('org.manufacturer.network.Car');
await assetRegistry.update(purchase.car);
}
但是脚本文件给出了Transaction processing function transferCar must have 1 function argument of type transaction.
错误
如何在单个script.js
文件中添加多个事务处理器函数?这是可能的还是我必须创建两个script.js
文件来处理交易?
这不是在script.js文件中定义两个事务的正确方法。
你的script.js文件应该是这样的:
/**
* New script file
* @param {org.manufacturer.network.Allocate} allocate - allocating the car from manufacturer to showroom
* @transaction
*/
async function transferCar(allocate){
allocate.car.showroom = allocate.newShowroom;
let assetRegistry = await getAssetRegistry('org.manufacturer.network.Car');
await assetRegistry.update(allocate.car);
}
/**
* New script file
* @param {org.manufacturer.network.Purchase} purchase - purchase the car by owner from showroom
* @transaction
*/
async function purchaseCar(purchase){
purchase.car.owner = purchase.newOwner;
let assetRegistry = await getAssetRegistry('org.manufacturer.network.Car');
await assetRegistry.update(purchase.car);
}
这是您可以在script.js文件中添加多个事务的方法。
我希望它会对你有所帮助。