Error: Expected a Resource or Concept
Error: Expected a Resource or Concept
当我尝试在 composer-playground 中执行事务时出现错误 "getAssetRegistry is returning null and the error message says assetRegistry is not defined"
/*这是我的 .cto 文件:*/
namespace org.acme.payrent
participant Authority identified by authorityId {
o String authorityId
}
participant Tenant identified by tenantEmailId {
o String tenantEmailId regex =/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o String tFirstName
o Address Address
o TBankDetails tBank
o Integer accountNo
}
participant Owner identified by ownerEmailId {
o String ownerEmailId regex =/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o String name
o String number regex=/^[0-9]*$/
o Integer bankaccountno
o Address propAddress
--> Tenant tnt
}
participant Bank identified by bankID {
o String bankID
o TBankDetails tBank
}
asset Property identified by propAddress {
o String propAddress
o Address propActAddress
o String tenantName
o Double rentAmount
}
concept Address {
o String houseNumber
o String street
o String city
o String country
}
concept TBankDetails {
o String bankName
o String ifscCode
o String branchName
}
concept Contact {
o String email regex =/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o String mobileNumber regex=/^[0-9]*$/
o String firstName
o String lastName
}
event E1{
o String email
o String mobileNumber regex=/^[0-9]*$/
o String tntName
o TBankDetails tntBankDetails
o Address propertyAddress
}
transaction Agreement{
--> Property property
o String owrName
o String tntName
o String email
o String propAddress
o String mobileNumber
o String bankName
o String ifscCode
o String branchName
}`
/* chaincode/logic.js 文件: */
`/**
* 订购车辆
* @param {org.acme.payrent.Agreement} 创建协议交易
* @交易
*/
function Agreement(tntObj)
{
debugger
var factory = getFactory(tntObj);
var Namespace = "org.acme.payrent";
var property = tntObj.propAddress;
var addTntEvent = factory.newEvent(Namespace, 'E1');
addTntEvent.email = tntObj.email;
addTntEvent.mobileNumber = tntObj.mobileNumber ;
addTntEvent.tntName = tntObj.tntName;
addTntEvent.tntBankName = tntObj.bankName;
addTntEvent.ifscCode = tntObj.ifscCode;
addTntEvent.branchName = tntObj.branchName;
var a = getAssetRegistry('org.acme.payrent.Property');
return getAssetRegistry('org.acme.payrent.Property')
.then(function(propertyRegistry){
return assetRegistry.update(property); });
}`
Access control file:permission.acl
`/**
* New access control file
*/
rule Default {
description: "Allow all participants access to all resources"
participant: "ANY"
operation: ALL
resource: "org.acme.payrent.*"
action: ALLOW
}
rule SystemACL {
description: "System ACL to permit all access"
participant: "ANY"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule Owner {
description: "Owner can add a Tenant"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule Bank {
description: "Bank can verify tenant's bank account"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule Govenment {
description: "To verify property belongs to owner"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}`
您的代码存在一些问题
- 预期资源或概念的原始问题是后者 - 这没有正确提供给事件
- 您在分配给
property
时使用了错误的对象,因此您的 assetRegistry 更新将不起作用
- 您需要在分配给事件字段时定义概念值 - 请参阅代码
- 已经离开 console.logs 所以你可以看到输出
- 您需要为您的交易提供更多数据(例如,概念地址字段)
- 下面有一个 rentAmount 分配 - 您需要删除 - 它在那里,所以您可以看到
Property
资产已更新,因为它应该由交易 Agreement
/*
* 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 transaction processor function.
* @param {org.acme.payrent.Agreement} tntObj The sample transaction instance.
* @transaction
*/
function Agreement(tntObj)
{
var factory = getFactory();
var Namespace = "org.acme.payrent";
var property = tntObj.property; // please note
console.log('property is ' + property);
var addTntEvent = factory.newEvent(Namespace, 'E1');
addTntEvent.email = tntObj.email;
addTntEvent.mobileNumber = tntObj.mobileNumber ;
addTntEvent.tntName = tntObj.tntName;
var tntBankDetails = factory.newConcept(Namespace, 'TBankDetails');
tntBankDetails.bankName = tntObj.bankName;
tntBankDetails.ifscCode = tntObj.ifscCode;
tntBankDetails.branchName = tntObj.branchName;
addTntEvent.tntBankDetails = tntBankDetails;
var conceptAddress = factory.newConcept(Namespace, 'Address');
conceptAddress.houseNumber = '10';
conceptAddress.street = '20';
conceptAddress.city = 'Mainz';
conceptAddress.country = 'DE';
addTntEvent.propertyAddress = conceptAddress;
emit(addTntEvent);
//remove this! var a = getAssetRegistry('org.acme.payrent.Property');
property.rentAmount =44.22 ; /// so you can see the value change on the asset in playground etc
return getAssetRegistry('org.acme.payrent.Property')
.then(function(propertyRegistry) {
return propertyRegistry.update(property);
});
}
当我尝试在 composer-playground 中执行事务时出现错误 "getAssetRegistry is returning null and the error message says assetRegistry is not defined"
/*这是我的 .cto 文件:*/
namespace org.acme.payrent
participant Authority identified by authorityId {
o String authorityId
}
participant Tenant identified by tenantEmailId {
o String tenantEmailId regex =/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o String tFirstName
o Address Address
o TBankDetails tBank
o Integer accountNo
}
participant Owner identified by ownerEmailId {
o String ownerEmailId regex =/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o String name
o String number regex=/^[0-9]*$/
o Integer bankaccountno
o Address propAddress
--> Tenant tnt
}
participant Bank identified by bankID {
o String bankID
o TBankDetails tBank
}
asset Property identified by propAddress {
o String propAddress
o Address propActAddress
o String tenantName
o Double rentAmount
}
concept Address {
o String houseNumber
o String street
o String city
o String country
}
concept TBankDetails {
o String bankName
o String ifscCode
o String branchName
}
concept Contact {
o String email regex =/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o String mobileNumber regex=/^[0-9]*$/
o String firstName
o String lastName
}
event E1{
o String email
o String mobileNumber regex=/^[0-9]*$/
o String tntName
o TBankDetails tntBankDetails
o Address propertyAddress
}
transaction Agreement{
--> Property property
o String owrName
o String tntName
o String email
o String propAddress
o String mobileNumber
o String bankName
o String ifscCode
o String branchName
}`
/* chaincode/logic.js 文件: */ `/** * 订购车辆 * @param {org.acme.payrent.Agreement} 创建协议交易 * @交易 */
function Agreement(tntObj)
{
debugger
var factory = getFactory(tntObj);
var Namespace = "org.acme.payrent";
var property = tntObj.propAddress;
var addTntEvent = factory.newEvent(Namespace, 'E1');
addTntEvent.email = tntObj.email;
addTntEvent.mobileNumber = tntObj.mobileNumber ;
addTntEvent.tntName = tntObj.tntName;
addTntEvent.tntBankName = tntObj.bankName;
addTntEvent.ifscCode = tntObj.ifscCode;
addTntEvent.branchName = tntObj.branchName;
var a = getAssetRegistry('org.acme.payrent.Property');
return getAssetRegistry('org.acme.payrent.Property')
.then(function(propertyRegistry){
return assetRegistry.update(property); });
}`
Access control file:permission.acl
`/**
* New access control file
*/
rule Default {
description: "Allow all participants access to all resources"
participant: "ANY"
operation: ALL
resource: "org.acme.payrent.*"
action: ALLOW
}
rule SystemACL {
description: "System ACL to permit all access"
participant: "ANY"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule Owner {
description: "Owner can add a Tenant"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule Bank {
description: "Bank can verify tenant's bank account"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule Govenment {
description: "To verify property belongs to owner"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}`
您的代码存在一些问题
- 预期资源或概念的原始问题是后者 - 这没有正确提供给事件
- 您在分配给
property
时使用了错误的对象,因此您的 assetRegistry 更新将不起作用 - 您需要在分配给事件字段时定义概念值 - 请参阅代码
- 已经离开 console.logs 所以你可以看到输出
- 您需要为您的交易提供更多数据(例如,概念地址字段)
- 下面有一个 rentAmount 分配 - 您需要删除 - 它在那里,所以您可以看到
Property
资产已更新,因为它应该由交易Agreement
/* * 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 transaction processor function. * @param {org.acme.payrent.Agreement} tntObj The sample transaction instance. * @transaction */ function Agreement(tntObj) { var factory = getFactory(); var Namespace = "org.acme.payrent"; var property = tntObj.property; // please note console.log('property is ' + property); var addTntEvent = factory.newEvent(Namespace, 'E1'); addTntEvent.email = tntObj.email; addTntEvent.mobileNumber = tntObj.mobileNumber ; addTntEvent.tntName = tntObj.tntName; var tntBankDetails = factory.newConcept(Namespace, 'TBankDetails'); tntBankDetails.bankName = tntObj.bankName; tntBankDetails.ifscCode = tntObj.ifscCode; tntBankDetails.branchName = tntObj.branchName; addTntEvent.tntBankDetails = tntBankDetails; var conceptAddress = factory.newConcept(Namespace, 'Address'); conceptAddress.houseNumber = '10'; conceptAddress.street = '20'; conceptAddress.city = 'Mainz'; conceptAddress.country = 'DE'; addTntEvent.propertyAddress = conceptAddress; emit(addTntEvent); //remove this! var a = getAssetRegistry('org.acme.payrent.Property'); property.rentAmount =44.22 ; /// so you can see the value change on the asset in playground etc return getAssetRegistry('org.acme.payrent.Property') .then(function(propertyRegistry) { return propertyRegistry.update(property); }); }