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

标签 javascript node.js hyperledger-composer

当我调用名为 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/

相关文章:

javascript - 大数的 karatsuba 乘法在 javascript 中失败

docker - 无法设置 IP 表 : Unable to enable NAT rule

hyperledger - 如何在网络上部署 Hyperledger Fabric 并在其上运行 Hyperledger Composer?

javascript - window.location.hash 在 IE11 中不起作用

javascript - JSDoc - 带有部分创建的类型定义

javascript - D3 在鼠标悬停时更改路径描边的颜色

linux - 将所有图像放入数据库或文件夹中

node.js - NodeJs - Fluent-FFMPEG 找不到 FFMPEG

mysql结果循环内的node.js回调

hyperledger-fabric - super 账本 : Not able to submit a transaction if one peer is down