Previously I developed my application on Hyperledger Composer. Now I'm trying to migrate the application to Hyperledger Fabric 1.4.
I implemented the Commercial-Paper tutorial given the Fabric 1.4 docs,which you can find here. Everything works fine.
Now I want to tailor this to my application and want to define more assets.
They have a file paper.js at commercial-paper/organization/digibank/contract/lib, is this the definition of the "paper" asset?
If I need to define additional assets, do I also create a file myasset.js at the same location and then call in the smart contract?
or is there a better way to define assets?
PS: I am trying to map the assets from Hyperledger composer to Hyperledger fabric 1.4.
Additionally how do you define relationships among assets and participants or other assets? In Composer we used to use --> to define relationships, how do we achieve the same thing fabric-1.4?
I believe I found the answer to my own question and I hope this would help anyone who is in a similar situation (Moving from Hyperledger Composer to Fabric 1.4)
ctx.stub.putState(key, data);
We simply use the above code to add an asset. A very simplified version is found in fabcar example.
async createCar(ctx, carNumber, make, model, color, owner) {
console.info('============= START : Create Car ===========');
const car = {
color,
docType: 'car',
make,
model,
owner,
};
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car)));
console.info('============= END : Create Car ===========');
}
Here we are adding a car, which is an asset.
In the commercial-paper example, they have done this using an Object-Oriented Approach. With paper.js they just create a 'paper' object (paper class extends state class. State class has the methods to make and split keys, which will be used later), then pass it to 'paperlist' which then uses the methods defined in statelist.js (paperlist class extends statelist class, which has all the methods to write the state onto the ledger) to create this asset using the following code
async addState(state) {
let key = this.ctx.stub.createCompositeKey(this.name, state.getSplitKey());
let data = State.serialize(state);
await this.ctx.stub.putState(key, data);
}
Here you can observe that the key is generated using the methods from the state class, which was inherited by the paper class.
And coming to the last question about relationships, I haven't found a concrete answer yet, but I believe you can achieve this by passing the participant ID or the asset id (Eg: A User is identified by userId, so we just pass the userId) in the data object.
In hindsight, this question looks really dumb, but I hope it helps some people out.
Please feel free to correct my understanding of the Hyperledger Examples. I'm here to learn :)