Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Blockchain by (12.7k points)

In the "basic-sample-network" or "trade-network" or "marbles-demo" sample of Hyperledger Fabric Composer - once the transaction is submitted then it checks for the presence of the asset ID in the database. However, it does not check if the new owner (participant) is actually present. How to check that the new owner is actually present in the database created?

1 Answer

0 votes
by (29.5k points)

Hi, it refer to the following code checks for the presence of both participant and the asset

/**
  * Trade a marble to a new player
  * @param {org.hyperledger_composer.marbles.TradeMarble} tradeMarble - the trade marble transaction
  * @transaction
  */
 function tradeMarble(tradeMarble) {
   return getParticipantRegistry('org.hyperledger_composer.marbles.Player')
     .then(function(playerRegistry) {
       return playerRegistry.exists(tradeMarble.newOwner.getIdentifier())
     })
      .then(function(exists) {
       if(!exists) {
         throw Error('Invalid participant id')
       } else {
        return getAssetRegistry('org.hyperledger_composer.marbles.Marble')
         .then(function (assetRegistry) {
          tradeMarble.marble.owner = tradeMarble.newOwner;
          return assetRegistry.update(tradeMarble.marble);
      });
       }
     })
 }

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...