"How to fix 'Error: Invalid or missing identifier' in hyperledger composer"



当我调用名为IntentForSale的交易时,我收到"错误:命名空间org.example.property中的类型属性列表标识符无效或缺失"

我试图改变 let propertyListing = factory.newResource(propertynamespace, 'Property', tx.PID(;让 propertyListing = factory.newResource(propertynamespace, 'PropertyListing', tx.PID(;并检查了我的模型.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"
    }

点击查看错误截图它应该给交易成功

看,在IntentForSale交易模型中,您没有归因PLID,并且您正在通过事务逻辑中的这个低谷。我认为您要做的是创建一个新资源,您需要给它一些 id。所以是这样的:

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

最新更新