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 9, 2018 in Blockchain by Shashank
• 10,400 points
1,209 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 9, 2018 by aryya
• 7,450 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 11, 2018 in Blockchain by Perry
780 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,100 points
3,428 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 15, 2018 in Blockchain by Perry
• 17,100 points
16,854 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
655 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
1,743 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,263 views
+1 vote
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP