How do I validate the presence of participant owner in Asset transfer transaction?

0 votes

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?

Aug 8, 2018 in Blockchain by Shashank
• 10,350 points
412 views

1 answer to this question.

0 votes

I found the exact solution and syntax.. This is for the marbles trading demo and it checks for 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);
      });
       }
     })
 }
answered Aug 8, 2018 by ariaholic
• 7,340 points

Related Questions In Blockchain

+1 vote
1 answer

How do i change the names of validating peers in IBM Bluemix blockchain?

IBM Bluemix Blockchain service Hyperledger Fabric v0.6 will ...READ MORE

answered Apr 10, 2018 in Blockchain by Perry
114 views
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,020 points
464 views
0 votes
1 answer

How do I get the balance of an account in Ethereum?

On the Web: (Not programmatic, but for completeness...) ...READ MORE

answered Nov 14, 2018 in Blockchain by Perry
• 17,020 points
267 views
0 votes
1 answer

Hyperledger Composer rest server NPM versions

The Hyperledger Composer pre-requisites can be installed ...READ MORE

answered Jul 13, 2018 in Blockchain by Christine
• 15,790 points
106 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
173 views
0 votes
1 answer