错误:非数字(未知)预期类型Double

时间:2019-03-18 11:41:35

标签: transactions hyperledger-composer

我正在Hyperledger Composer中开发一个小程序。我做了一些公司(参与者)和产品(资产)。此外,我有一笔交易可以在公司之间进行产品交易。现在,我正在尝试使用qualityControl来检查产品是否具有必要的质量。没有qualityControl,我的事务将正常工作,但是当我使用qualityControl时,会出现错误:“ t:实例org.master.MaterialSupplier#MS字段accountBalance中的模型违规具有值非数字(未知)预期类型Double”

如果我做对了,脚本文件中的代码有问题,但是我不知道它是什么或如何解决。...

模型文件:

namespace org.master

// BASE DEFINTIONS

abstract participant Business identified by businessId {
  o String businessId
}

participant MaterialSupplier extends Business {
  o String materialSupplierName
  o Double accountBalance
  // Alle vorhandenen Materialien anzeigen
}

concept MaterialDetails {
  --> MaterialSupplier make
  o String materialName
  o String materialColour optional
  o String batch
  o Double amount
}

asset Material identified by materialId {
  o String materialId
  o MaterialDetails materialDetails
  o QualityControlMaterial [] qualityControlsMaterial optional
  --> Business owner
}

transaction InternMaterialSupplier {
  --> MaterialSupplier newOwner
  --> Material material
  o Double unitCount
  o DateTime arrivalDateTime
}

transaction MaterialSupplierToProducer {
  --> Producer newOwner
  --> Material material
  o Double unitCount
  o Double unitPrice
  o Double minQuality 
  o Double maxQuality 
  o Double penaltyFactor
  o DateTime arrivalDateTime
  --> MaterialSupplier materialSupplier
  --> Producer producer
}

participant Producer extends Business {
  o String producerName
  o Double accountBalance
  // Alle vorhandenen Materialien + Module anzeigen
}

transaction QualityControlMaterial {
  o Double qualityDegree
  --> Material material
}

脚本文件:

/**
 * @param {org.master.MaterialSupplierToProducer} materialSupplierToProducer - the materialSupplierToProducer to be processed
 * @transaction
 */
async function test2(materialSupplierToProducer) {

    const material = materialSupplierToProducer.material;
    materialSupplierToProducer.material.owner = materialSupplierToProducer.newOwner;
    let assetRegistry = await getAssetRegistry('org.master.Material');
    await assetRegistry.update(materialSupplierToProducer.material);

    let payOut = materialSupplierToProducer.unitPrice * materialSupplierToProducer.unitCount;

    if(material.qualityControlsMaterial) {
      material.qualityControlsMaterial.sort(function (a,b) {
        return (a.qualityDegree - b.qualityDegree);
      });

      const lowestQuality = material.qualityControlsMaterial[0];
      const highestQuality = material.qualityControlsMaterial[material.qualityControlsMaterial.length - 1];

      let penalty = 0;
      console.log('Lowest quality reading: ' + lowestQuality.qualityDegree);
      console.log('Highesst quality reading: ' + highestQuality.qualityDegree);

      if(lowestQuality.qualityDegree < materialSupplierToProducer.minQuality) {
        penalty += (materialSupplierToProducer.minQuality - lowestQuality.qualityDegree) * materialSupplierToProducer.penaltyFactor;
        console.log('Min quality penalty: ' + penalty);
      }

      if(highestQuality.qualityDegree > materialSupplierToProducer.maxQuality) {
        penalty += (highestQuality.qualityDegree - materialSupplierToProducer.maxQuality) * materialSupplierToProducer.penaltyFactor;
        console.log('Max quality penalty: ' + penalty);
      }

      payOut -= (penalty * material.unitCount);

      if(payOut < 0) {
        payOut = 0;
      }
    }   

    console.log('Payout: ' + payOut);
    materialSupplierToProducer.materialSupplier.accountBalance += payOut;
    materialSupplierToProducer.producer.accountBalance -= payOut;

    console.log('MaterialSupplier: ' + materialSupplierToProducer.$identifier + 'new balance: ' + materialSupplierToProducer.materialSupplier.accountBalance);
    console.log('Producer: ' + materialSupplierToProducer.$identifier + 'new balance: ' + materialSupplierToProducer.producer.accountBalance);

    const materialSupplierRegistry = await getParticipantRegistry('org.master.MaterialSupplier');
    await materialSupplierRegistry.update(materialSupplierToProducer.materialSupplier);

    const producerRegistry = await getParticipantRegistry('org.master.Producer');
    await producerRegistry.update(materialSupplierToProducer.producer);
}

/**
 * @param {org.master.QualityControlMaterial} qualityControlMaterial - the QualityControlMaterial transaction
 * @transaction
 */
async function qualityControlMaterial(qualityControlMaterial) {

    const material = qualityControlMaterial.material;

    console.log('Adding quality ' + qualityControlMaterial.qualityDegree + ' to shipment ' + material.$identifier);

    if (material.qualityControlsMaterial) {
        material.qualityControlsMaterial.push(qualityControlMaterial);
    } else {
        material.qualityControlsMaterial = [qualityControlMaterial];
    }

    // add the quality control to the material
    const materialRegistry = await getAssetRegistry('org.master.Material');
    await materialRegistry.update(material);
}

访问控制:

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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
}

感谢您的帮助!

0 个答案:

没有答案