I am new to hyperledger and writing chaincode in golang for a fictional farm product. The flow of main stakeholders of the supply chain system are as follows:
Farm -> logistics -> aggregation center -> logistics ->cold storage -> logistics -> distributor -> logistics -> retailer -> consumer
As you can see at each stage the data format will be different. For eg at first stage the data format would be like this:
{
"harvestDate":"xx-xx-xxxx",
"farmerName":"abc",
"batchId":"123456",
// so on
}
So the first state of the ledger for the batch id 123456 will be like above data format. Now, if the product is now in logistics phase then data can be like:
{
"vehicleNumber":"ABCDE1234",
"driverName":"XYZ",
"loadingDate":"xx-xx-xxxx",
// so on
}
If I input this data into hyperledger ledger then the data format will completely get changed. So if I query the current hyperledger, I will get the above logistics data format.
In frontend we want to show data like this:
Farm Details -> Logistics Details -> Aggregation Center details -> logistics details -> distributor details -> retailer details -> end customer details
The number of stakeholders can be dynamic depending on the product some may have 4 stakeholders or 6 stakeholders (like above).
Now, if the frontend have to query the data of the product based on batch id of the product it will get different data format for each stage. So I want to know how the frontend will be able to get to know that which data format belongs to which stage in the supply chain so that frontend can bind it accordingly ?
I tried to copy previous data format into new data format from the past stage and came up something like this
- Farm
{
“batchId”:123456, //unique identifier to identify the batch
“cropName”:”Rice”,
“cropVariety”:”Basmati”,
“farmLocation”:”XYZ”,
“farmer”:”ABC”,
“harvestingDate”:”2023-11-06”
}
- Logistics
{
// copied same above data
"vehicleNumber":"ABCDE1234",
"driverName":"XYZ",
"loadingDate":"xx-xx-xxxx",
}
- Aggregation Center
{
// copied same above data
"aggregationLocation":"XYZ",
"dateOfAggregation:"xx-xx-xxxx",
}
As you can see I am just copying the previous state into the new state which can make the ledger data very big in format if there are many stakeholders in the system.
I want to know to make the system much more dynamic so that frontend can easily query the data of a product depending on a batch id, and show the product details appropriately according to the different stages of the product.
I am using Hyperledger fabric v2.5
Thanks in advance