我正在尝试在Hyperledger Composer中建立业务模型。我有2位参与者:供应商和客户以及一项资产,即交货。我有2个事务:createDelivery和receiveDelivery。 createDelivery创建资产,receiveDelivery更改交付状态。
客户具有字段库存,而我的目标是进行设置,以便在通过receiveDelivery交易时,客户资产中的库存字段将通过交货数量进行更新。
尝试调用confirmDelivery时出现错误,错误如下:注意01是客户ID。
这是我的模型文件:
namespace org.example
participant customer identified by CompanyID {
o String CompanyID
o String Name
o Integer Inventory
}
participant vendor identified by CompanyID {
o String CompanyID
o String Name
}
asset Delivery identified by DeliveryID {
o String DeliveryID
o String Material
o Integer Quantity
o DeliveryStatus Status
--> vendor vendor
--> customer customer
}
enum DeliveryStatus {
o Created
o Received
}
transaction createDelivery {
o String DeliveryID
o String Material
o Integer Quantity
--> vendor vendor
--> customer customer
}
transaction receiveDelivery {
--> Delivery Delivery
}
下面是脚本文件:
'use strict';
/**
* Create Delivery.
* @param {org.example.createDelivery} createDelivery
* @transaction
*/
async function createDelivery(createDelivery) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const NS = 'org.example';
var delivery = factory.newResource(NS, 'Delivery', createDelivery.DeliveryID);
delivery.customer = factory.newRelationship(NS, 'customer', createDelivery.customer.getIdentifier());
delivery.vendor = factory.newRelationship(NS, 'vendor', createDelivery.vendor.getIdentifier());
delivery.Material = createDelivery.Material;
delivery.Quantity = createDelivery.Quantity;
delivery.Status = "Created";
//save the asset
const assetRegistry = await getAssetRegistry(delivery.getFullyQualifiedType());
await assetRegistry.add(delivery);
}
/**
* Receive Delivery.
* @param {org.example.receiveDelivery} receiveDelivery
* @transaction
*/
async function receiveDelivery(receiveDelivery) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const NS = 'org.example';
var delivery = receiveDelivery.Delivery
var quantity = delivery.Quantity
const customer = await getParticipantRegistry(delivery.customer.getIdentifier());
customer.Inventory += quantity;
await customer.update(customer)
delivery.Status = 'Received'
}
默认ACL:
rule NetworkAdminUser {
description: "Grant business network administrators full access to user resources"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "**"
action: ALLOW
}
rule NetworkAdminSystem {
description: "Grant business network administrators full access to system resources"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule GrantSysAccess {
description: "Grant access to all Participants to target system registries"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
我已经尝试解决该错误已有一个小时了,如果您能为我提供帮助,我们将不胜感激。
答案 0 :(得分:1)
您的receive
交易有一些错误,但是下面的代码应该可以工作。
一些注意事项:
代码示例
/**
* Receive Delivery.
* @param {org.example.receiveDelivery} receiveDelivery
* @transaction
*/
async function receiveDelivery(receiveDelivery) { // eslint-disable-line no-unused-vars
// const factory = getFactory();
const NS = 'org.example';
var delivery = receiveDelivery.Delivery;
var quantity = delivery.Quantity;
//Get The Customer Participant Registry, get the Specific Customer, then update
const customerRegistry = await getParticipantRegistry(NS+'.customer');
var customer = await customerRegistry.get( delivery.customer.getIdentifier() );
customer.Inventory += quantity;
await customerRegistry.update(customer);
//Get the Delivery Asset registry, then Update
const deliveryRegistry = await getAssetRegistry(NS+'.Delivery');
delivery.Status = 'Received';
await deliveryRegistry.update(delivery);