gpt4 book ai didi

javascript - 尝试创建交易时,在 hyperledger Composer 中出现错误 : Expected a Resource or Concept.

转载 作者:行者123 更新时间:2023-12-02 21:54:56 26 4
gpt4 key购买 nike

我不知道为什么我的代码不起作用。这是:

牛奶.cto

 * 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.
*/

/**
* Sour milk business network definition.
*/
namespace org.example.milk

concept Address {
o String street
o String city default ="Gabrovo"
o String country default = "Bulgaria"
}

asset SourMilk identified by batchId {
o Integer quantity
o String batchId
--> Producer producer
--> Owner owner
o Address origin
o String description
o Double fats default=4.0
o Double saturatedFats default=4.0
o Double kilocalories default=66.0
o Double lactose default=4.6
o Double protein default=3.2
o Double sodium default=0.1
o Boolean checked default=false
o Boolean confirmed default=false
--> Inspector checkingInspector
}

participant Producer identified by producerId {
o String producerId
o String firstName
o String lastName
o Address address
}

participant Owner identified by ownerId {
o String ownerId
o String firmName
o String firstNameOfCEO
o String lastNameOfCEO
o Address address
o String description
}

participant Inspector identified by inspectorId {
o String inspectorId
o String firstName
o String lastName
o Address address
o String institution default="HEI"
}
transaction QualityCheck {
--> SourMilk batch
--> Inspector inspector
o Boolean approval
}

lib/sample.js

/*
* 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.
*/

/* global getAssetRegistry */

/**
* Confirmation
* @param {org.example.milk.QualityCheck} batch, inspector, approval
* @transaction
*/
async function QualityCheck(batch, inspector, approval)
{
batch.checked=true
batch.confirmed=approval

// Get the asset registry for the asset.
const assetRegistry = await getAssetRegistry('org.example.milk.SourMilk');
// Update the asset in the asset registry.
await assetRegistry.update(batch.checked);
}

权限.acl

/*
* 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.
*/

/**
* Sample access control list.
*/
rule ProducersCanReadEverything {
description: "Allow producers read access to all resources"
participant: "org.example.milk.Producer"
operation: READ
resource: "org.example.milk.*"
action: ALLOW
}

rule OwnersCanReadEverything {
description: "Allow owners read access to all resources"
participant: "org.example.milk.Owner"
operation: READ
resource: "org.example.milk.*"
action: ALLOW
}

rule InspectorCanReadEverything {
description: "Allow inspectors read access to all resources"
participant: "org.example.milk.Inspector"
operation: READ
resource: "org.example.milk.*"
action: ALLOW
}

rule InspectorCanCheckQuality {
description: "Allow inspectors to check quality"
participant: "org.example.milk.Inspector"
operation: CREATE
resource: "org.example.milk.QualityCheck"
action: ALLOW
}

rule ProducerHasFullAccessToTheirAssets {
description: "Allow all participants full access to their assets"
participant(p): "org.example.milk.Producer"
operation: ALL
resource(r): "org.example.milk.SourMilk"
condition: ((r.producer.getIdentifier() === p.getIdentifier()) && !r.checked && !r.confirmed)
action: ALLOW
}


rule SystemACL {
description: "System ACL to permit all access"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
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 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
}

为什么我在尝试创建事务时会收到此错误:错误:需要资源或概念我相信我输入的值是正确的。'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''

最佳答案

试试这个

await assetRegistry.update(batch);

在质量检查功能中

关于javascript - 尝试创建交易时,在 hyperledger Composer 中出现错误 : Expected a Resource or Concept.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60029669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com