我如何在 hyperledger composer 中管理我的资产?
How can I manage my assets in hyperledger composer?
在我的 hyperledger composer 项目中,我有一种药物作为资产。药品种类繁多,但所有药品都需要获得批准才能在供应链中生产和分销。
我可以在区块链中存储一个允许的资产列表,一个可以增长或缩小的列表吗?还是我必须将其存储在链下?
编辑:修正了语法错误。
根据你对 Riccardo Bonesi 的回复,我建议这样
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
}
现在在你的 .js
文件中你可以做这样的事情
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
};
};
现在当然基于 composer 版本,可能需要调整一些语法,但这是如何维护映射的一般思路。
在我的 hyperledger composer 项目中,我有一种药物作为资产。药品种类繁多,但所有药品都需要获得批准才能在供应链中生产和分销。
我可以在区块链中存储一个允许的资产列表,一个可以增长或缩小的列表吗?还是我必须将其存储在链下?
编辑:修正了语法错误。
根据你对 Riccardo Bonesi 的回复,我建议这样
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
}
现在在你的 .js
文件中你可以做这样的事情
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
};
};
现在当然基于 composer 版本,可能需要调整一些语法,但这是如何维护映射的一般思路。