我是超级账本的初学者。我的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
文件来处理交易?
答案 0 :(得分:2)
这不是在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文件中添加多个事务的方法。
希望它能对您有所帮助。