如何在脚本文件中添加两个事务功能?

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

我是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文件来处理交易?

hyperledger-fabric hyperledger-composer
1个回答
3
投票

这不是在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文件中添加多个事务的方法。

我希望它会对你有所帮助。

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