Hyperledger Fabric: Changing component item owner automatically with its parent

0 votes

This is my cto:

asset Item identified by itemId{
o String itemId
o String name
o String idgId
o String serialNumber
o String comment
--> BU owner
--> Item [] items optional
}
abstract participant BU identified by buId{
    o String buId
    o String name
    o String country
    o String city
}
participant Manufacturer extends BU{
}
participant Assembler extends BU{
}

And chaincode:

function tradeCommodity(trade) {
trade.item.owner = trade.newOwner;
return getAssetRegistry('org.dps.track.Item')
    .then(function (assetRegistry) {
        var tradeNotification = getFactory().newEvent('org.dps.track',       'TradeNotification'); 
        tradeNotification.item = trade.item;
        emit(tradeNotification);

        // persist the state of the commodity
        return assetRegistry.update(trade.item);
    });

}

then i make two items: I1 and I2 - which will be components of third item I3 like this:

    {
    "$class": "org.dps.track.Item",
    "itemId": "I1",
    "name": "c1",
    "idgId": "123",
    "serialNumber": "123",
    "comment": "component1",
    "owner": "resource:org.dps.track.Assembler#BU2"
  },
  {
    "$class": "org.dps.track.Item",
    "itemId": "I2",
    "name": "c2",
    "idgId": "456",
    "serialNumber": "456",
    "comment": "component2",
    "owner": "resource:org.dps.track.Assembler#BU2"
  },
  {
    "$class": "org.dps.track.Item",
    "itemId": "I3",
    "name": "complex",
    "idgId": "789",
    "serialNumber": "789",
    "comment": "item consists of items",
    "owner": "resource:org.dps.track.Assembler#BU2",
    "items": [
      "resource:org.dps.track.Item#I1",
      "resource:org.dps.track.Item#I2"
    ]
  }

Now, I want I1 and I2 to change owner automatically when I3 changes the owner. How can I do this?

Nov 16, 2018 in Blockchain by digger
• 27,620 points
48 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can try something like this:

/**
 * Sample transaction processor function.
 * @param {org.dps.track.Trade } trade The sample transaction instance.
 * @transaction
 */
async function tradeCommodity(trade) {

    const factory = getFactory();
    trade.item.owner = trade.newOwner;
    var list = [];
    if (trade.item.items && trade.item.items.length > 0) {
        trade.item.items.forEach((asset) => {
        list.push(asset);
        });
    }  


    const assetRegistry = await getAssetRegistry('org.dps.track.Item');


    // persist the state of the current ITEM
    await assetRegistry.update(trade.item);

    for (var i = 0; i < list.length; ++i) {

         let res = await assetRegistry.get(list[i].getIdentifier());
         res.owner = factory.newRelationship('org.dps.track', 'Assembler', trade.newOwner.getIdentifier());
         // persist the state of the ITEM with new owner as a relationship
         await assetRegistry.update(res);
    }

}
answered Nov 16, 2018 by Omkar
• 65,840 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

Not Able to register a user with Hyperledger-Fabric v1.1 preview

The error: "Certificate not found with AKI 'e729224e8b3f31784c8a93c5b8ef6f4c1c91d9e6e577c45c33163609fe40011' ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,710 points
287 views
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 27,620 points
37 views
+1 vote
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.