I am a beginner in hyperledger. My model.cto
file has two transaction processor function one for transferring the car from manufacturer to the showroom and another one is for transferring the car from showroom to owner. model.cto
file is given below,
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
}
So, I want to add two functions in my script.js
file, so that I could perform my transactions. My script.js
file is given below
/**
* 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);
}
But the script file is giving error as Transaction processing function transferCar must have 1 function argument of type transaction.
How to add multiple transaction processor functions in a single script.js
file?
Is that possible or I have to create two script.js
file to handle the transactions?
That is not the correct way to define two transactions in the script.js file.
Your script.js file should be like this:
/**
* 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);
}
This is how you can add more than one transaction in the script.js file.
I hope it will help you.