deltu100
deltu100

Reputation: 581

How can I manage my assets in hyperledger composer?

In my hyperledger composer project I have a medicine as an asset. There are different types of medicine, but all medicine need to be approved before they are allowed to be produced and distributed in the supply chain.

Can I store a list of allowed assets in the blockchain, a list which can grow or shrink? Or do I have to store it off-chain?

edit: grammar mistake fixed.

Upvotes: 0

Views: 98

Answers (1)

Varun Agarwal
Varun Agarwal

Reputation: 1587

Based on your reply to Riccardo Bonesi, I suggest something like this

asset AllowedMedicines identified by id {
  o String id
  o Medicines[] medicines
}

concept Medicines {
  o String medicineId
  o String medicineName
  o Participants[] allowedParticipants
}

concept Participants {
  o String participantId // either this is one below
  --> Participant somePerson
  // Any specific meta data you want to store
}

Now in your .js files you can do something like this

const allowedMedicines = await registry.get(id);
const participant; // The person you are checking for
const medicineId; // The medicine against which you are checking
const medicines = allowedMedicines.medicines;
if (medicines.medicineId.contains(medicineId)) {
  // Medicine is in the list;
  let allowedParticipants = medicines.allowedParticipants;
  if (allowedParticipants.contains(participant) {
     // The participant is allowed access to the medicine
  };
};

Now of course based on the composer version, some syntax may need to be tweaked, but is the general idea of how you can maintain a mapping.

Upvotes: 2

Related Questions