gpt4 book ai didi

javascript - "How to fix ' 错误 : Invalid or missing identifier ' in hyperledger composer"

转载 作者:行者123 更新时间:2023-11-30 06:14:18 25 4
gpt4 key购买 nike

当我调用名为 IntentForSale 的事务时,我收到“错误:命名空间 org.example.property 中类型 PropertyListing 的标识符无效或缺失”

我试图改变 let propertyListing = factory.newResource(propertynamespace, 'Property', tx.PID);让 propertyListing = factory.newResource(propertynamespace, 'PropertyListing', tx.PID);并检查了我的 model.cto。

模型.cto

/* This namespace helps in idetifying the entities for the network.    */
namespace org.example.property

/* Asset Property identified by a striing PID
This is used to maintain the properties which are registered in the system.
*/

asset Property identified by PID {
o String PID
o String owner
o Integer mktprice
o String RegistrationDate
o String PropertyType
o String Location
o String Status default = "Registered"
o Boolean Public
o Boolean Private
o Boolean IntentOfSale

}

/* Asset PropertyListing identified by a striing PLID
This is used to maintain the properties which are listed for sale in the system.
*/
asset PropertyListing identified by PLID {

o String PLID
o String owner
o Integer mktprice
o String RegistrationDate
o String PropertyType
o String Location
o String Status default = "Intent Of Sale"
}
    /* Participant Buyer identified by a striing Bname
This is used to maintain the buyers who are part of the system.
*/
participant Buyer identified by Bname {
o String Bname
o String Bemail
o Integer IdentityNo //Passport, SSN, Aadhar etc.
o String Bnkname
o String Bnkaddress
o Integer AccNo
o String IFSC
o Integer Balance
}

/* Participant Seller identified by a striing Sname
This is used to maintain the sellers who are part of the system.
*/
participant Seller identified by Sname {
o String Sname
o String Semail
o Integer IdentityNo
o String Bnkname
o String Bnkaddress
o Integer AccNo
o String IFSC
o Integer Balance
o String SaleDeedDocs
}

/* Participant Registrar identified by a striing Rname
This is used to maintain the registrar who are part of the system.
*/
participant Registrar identified by Rname {
o String Rname
o String Remail
}

/* Transaction Created
This is used to add new properties in the system.
*/
transaction Created {
o String PID
--> Property cproperty
}

transaction Registered {
o String PID
--> PropertyListing rpropertylisting
--> Buyer rbuyer
}

transaction IntentForSale {
--> Property iproperty
--> PropertyListing ipropertylisting
--> Seller iseller
}

脚本.js

    /**
* Transaction Created to put the property for sale in the system
* @param {org.example.property.IntentForSale} tx
* @transaction
*/

async function IntentForSale(tx){
console.log('Property IntentForSale Transaction');

//Getting the namespace and factory
const propertynamespace = 'org.example.property';
const factory = getFactory();

//Putting the property for sale
let propertyListing = factory.newResource(propertynamespace, 'PropertyListing', tx.PLID);
propertyListing.owner = tx.iseller.Sname;
propertyListing.mktprice = tx.iproperty.mktprice;
propertyListing.RegistrationDate = tx.iproperty.RegistrationDate;
propertyListing.PropertyType = tx.iproperty.PropertyType;
propertyListing.Location = tx.iproperty.Location;
propertyListing.Status = tx.iproperty.Status;

//Get the asset registry
let registry = await getAssetRegistry('org.example.property.PropertyListing');
// save the property
await registry.add(propertyListing);

}

当我通过这些时

    {
"$class": "org.example.property.IntentForSale",
"iproperty": "resource:org.example.property.Property#101",
"ipropertylisting": "resource:org.example.property.PropertyListing#102",
"iseller": "resource:org.example.property.Seller#shantanu"
}

click to see error screenshot它应该使交易成功

最佳答案

看,在 IntentForSale 交易模型中,您没有属性 PLID,并且您正在交易逻辑中传递这个低谷。我认为你想做的是创建一个新资源,你需要给它一些 id。也是这样的:

//Putting the property for sale
let propertyListing = factory.newResource(propertynamespace, 'PropertyListing', tx.transactionId);

关于javascript - "How to fix ' 错误 : Invalid or missing identifier ' in hyperledger composer",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57159911/

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