Hyperledger Composer操场设置演示删除

问题描述 投票:0回答:1

我有个问题。我正在使用Hyperledger Composer Playground,我正在使用事务SetupDemo进行测试。但是现在每次我使用SetupDemo运行测试时,我必须单独删除创建的参与者和资产。

是否有可能(一个函数或某个函数)一次删除所有这些?

谢谢你的帮助!!

hyperledger-composer
1个回答
0
投票

是的我可以添加我的代码。我以“车辆制造商 - 生命周期”为例,现在我正在更改变量名称。

这是我的模型文件。重要的部分是第一部分(第一部分和资产)

namespace org.master

// BASE DEFINTIONS

concept MaterialDetails {
  --> Manufacturer make
  o String materialName
  o String materialColour
  o Double amount
}

asset Material identified by materialId {
  o String materialId
  o MaterialDetails materialDetails
  --> Person owner optional
}

concept ModuleDetails {
  --> Manufacturer make
  o String moduleName
  o Double amount
}

asset Module identified by moduleId {
  o String moduleId
  o ModuleDetails moduleDetails
  --> Person owner optional
}

abstract participant Company identified by companyId {
  o String companyId
  o String name
}

participant Person identified by username {
  o String username
  o String email optional
}


// MANUFACTURE DEFINITIONS
participant Manufacturer extends Company {
}

participant Producer extends Company {
}

enum OrderStatus {
  o PLACED
  o SCHEDULED_FOR_MANUFACTURE
  o VIN_ASSIGNED
  o OWNER_ASSIGNED
  o DELIVERED
}

concept Options {
  o String trim
  o String interior
  o String[] extras
}

asset Order identified by orderId {
  o String orderId
  o MaterialDetails materialDetails
  o OrderStatus orderStatus
  o Options options
  --> Person orderer
}

transaction PlaceOrder {
  o String orderId
  o MaterialDetails materialDetails
  o Options options
  --> Person orderer
}

event PlaceOrderEvent {
  o String orderId
  o MaterialDetails materialDetails
  o Options options
  --> Person orderer
}

transaction UpdateOrderStatus {
  o OrderStatus orderStatus
  o String vin optional
  --> Order order
}

event UpdateOrderStatusEvent {
  o OrderStatus orderStatus
  o Order order
}


// REGULATOR DEFINITIONS
participant Regulator extends Company {
}

这是我的脚本文件:

// DEMO SETUP FUNCTIONS
/**
 * Create the participants to use in the demo
 * @param {org.master.SetupDemo} setupDemo - the SetupDemo transaction
 * @transaction
 */
async function setupDemo() { // eslint-disable-line no-unused-vars
    console.log('setupDemo');

    const factory = getFactory();
    const namespace = 'org.master';

    let people = ['Paul'];
    let materialSuppliers;

    const materials = {
        'MSLogistics': {
            'Wire1': [
                {
                    'materialId': 'W1',
                    'materialColour': 'Yellow',
                    'amount': 100
                }
            ],
            'Wire2': [
                {
                    'materialId': 'W2',
                    'materialColour': 'Blue',
                    'amount': 100
                }
            ],
            'Wire3': [
                {
                    'materialId': 'W3',
                    'materialColour': 'Black',
                    'amount': 100
                }
            ]
        },
        'MSProduction': {
        },
        'MSQualityControl': {
        }
    };

    // convert array names of people to be array of participant resources of type Person with identifier of that name
    people = people.map(function (person) {
        return factory.newResource(namespace, 'Person', person);
    });


    // create array of Manufacturer particpant resources identified by the top level keys in vehicles const
    materialSuppliers = Object.keys(materials).map(function (manufacturer) {
        const manufacturerResource = factory.newResource(namespace, 'Manufacturer', manufacturer);
        manufacturerResource.name = manufacturer;
        return manufacturerResource;
    });

    const regulator = factory.newResource(namespace, 'Regulator', 'VDA');
    regulator.name = 'VDA';

    // add the regulator
    const regulatorRegistry = await getParticipantRegistry(namespace + '.Regulator');
    await regulatorRegistry.add(regulator);

    // add the manufacturers
    const manufacturerRegistry = await getParticipantRegistry(namespace + '.Manufacturer');
    await manufacturerRegistry.addAll(materialSuppliers);

    // add the persons
    const personRegistry = await getParticipantRegistry(namespace + '.Person');
    await personRegistry.addAll(people);

    // add the vehicles
    const vehicleRegistry = await getAssetRegistry(namespace + '.Material');
    const vehicleResources = [];

    for (const manufacturer in materials) {
        for (const model in materials[manufacturer]) { 
            const vehicconstemplatesForModel = materials[manufacturer][model]; 
            vehicconstemplatesForModel.forEach(function(vehicconstemplate) { 
                const material = factory.newResource(namespace, 'Material', vehicconstemplate.materialId);
                material.owner = people[vehicleResources.length+1]; 
                material.materialDetails = factory.newConcept(namespace, 'MaterialDetails');
                material.materialDetails.make = factory.newResource(namespace, 'Manufacturer', manufacturer);
                material.materialDetails.materialName = model;
                material.materialDetails.materialColour = vehicconstemplate.materialColour;
                material.materialDetails.amount = vehicconstemplate.amount;

                vehicleResources.push(material);
            });
        }
    }
    await vehicleRegistry.addAll(vehicleResources);
}

这是访问控制:

rule PersonMakeOrder {
    description: "Allow Persons to create and view orders"
    participant(p): "org.master.Person"
    operation: CREATE
    resource(o): "org.master.Order"
    transaction(tx): "org.master.PlaceOrder"
    condition: (o.orderer.getIdentifier() == p.getIdentifier())
    action: ALLOW
}

rule PersonPlaceOrder {
    description: "Allow Persons to place orders and view they've done this"
    participant(p): "org.master.Person"
    operation: CREATE, READ
    resource(o): "org.master.PlaceOrder"
    condition: (o.orderer.getIdentifier() == p.getIdentifier())
    action: ALLOW
}

rule PersonReadOrder {
    description: "Allow Persons to place orders and view they've done this"
    participant(p): "org.master.Person"
    operation: READ
    resource(o): "org.master.Order"
    condition: (o.orderer.getIdentifier() == p.getIdentifier())
    action: ALLOW
}

rule ManufacturerUpdateOrder {
    description: "Allow manufacturers to view and update their own orders"
    participant(m): "org.master.Manufacturer"
    operation: UPDATE
    resource(o): "org.master.Order"
    transaction(tx): "org.master.UpdateOrderStatus"
    condition: (o.materialDetails.make.getIdentifier() == m.getIdentifier())
    action: ALLOW
}

rule ManufacturerUpdateOrderStatus {
    description: "Allow manufacturers to update order statuses and view they've done this"
    participant(m): "org.master.Manufacturer"
    operation: CREATE, READ
    resource(o): "org.master.UpdateOrderStatus"
    condition: (o.order.materialDetails.make.getIdentifier() == m.getIdentifier())
    action: ALLOW
}

rule ManufacturerReadOrder {
    description: "Allow manufacturers to view and update their own orders"
    participant(m): "org.master.Manufacturer"
    operation: READ
    resource(o): "org.master.Order"
    condition: (o.materialDetails.make.getIdentifier() == m.getIdentifier())
    action: ALLOW
}

rule ManufacturerCreateVehicles {
    description: "Allow manufacturers to create and view their vehicles"
    participant(m): "org.master.Manufacturer"
    operation: CREATE
    resource(v): "org.master.Material"
    transaction(tx): "org.master.UpdateOrderStatus"
    condition: (v.materialDetails.make.getIdentifier() == m.getIdentifier() && tx.orderStatus == "VIN_ASSIGNED")
    action: ALLOW
}

rule ManufacturerReadVehicles {
    description: "Allow manufacturers to create and view their vehicles"
    participant(m): "org.master.Manufacturer"
    operation: READ
    resource(v): "org.master.Material"
    condition: (v.materialDetails.make.getIdentifier() == m.getIdentifier())
    action: ALLOW
}

rule RegulatorAdminUser {
    description: "Let the regulator do anything"
    participant: "org.master.Regulator"
    operation: ALL
    resource: "**"
    action: ALLOW
}

rule ParticipantsSeeSelves {
    description: "Let participants see themselves"
    participant(p): "org.hyperledger.composer.system.Participant"
    operation: ALL
    resource(r): "org.hyperledger.composer.system.Participant"
    condition: (r.getIdentifier() == p.getIdentifier())
    action: ALLOW
}

rule NetworkAdminUser {
    description: "Grant business network administrators full access to user resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "**"
    action: ALLOW
}

rule System {
    description: "Grant all full access to system resources"
    participant: "org.**"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}
© www.soinside.com 2019 - 2024. All rights reserved.