简体   繁体   中英

getting an error when I am trying to add an asset through transaction in hyperledger composer

sample.cto file

  namespace org.example.basic

    asset Supplier identified by suppliername
    {
      o String suppliername
    }
    asset product identified by productname{
    o String productname
    -->Supplier supplier
    o Integer amount
    }



    transaction SampleTransaction {
      -->product productasset
      o String productname
      o String supplier
      o Integer amount
    }

logic.js file

/** * Sample transaction processor function. * @param {org.example.basic.SampleTransaction} tx The sample transaction instance. * @transaction */

async function createPost(tx) {

      var factory = getFactory();
      return getAssetRegistry("org.example.basic.product")
      .then(function(postAssetRegistry) {
       var productname=tx.productname
       newPost = factory.newResource("org.example.basic", "product", productname);
       newPost.productname = tx.productname;
       newPost.supplier = tx.supplier;
       newPost.amount=tx.amount;

       return postAssetRegistry.add(newPost);
  })





}

click here to view error image

In your transaction definition in the model file you are specifying a string, but in this line of the script newPost.supplier = tx.supplier; the newPost.supplier property is being enforced by Composer to be a relationship so would have a value something like org.example.basic.Supplier#qqa

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM