...by Daniel Szego
quote
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Saturday, July 7, 2018

Fabric composer tips and tricks - create a new participant


To create a new participant in Fabric composer in the transaction is pretty similar to creating an asset, you have to do the following steps:

0. Supposing you have a model file and a participant:

  asset participantName identified by <primkey> {
    o <type>  <primkey>
    o <type>  RequiredField1 
    o <type>  RequiredField2 
   ...
  }

1. get a factory object: it helps you to create other resources, events, assets, participants and so on.

  const factory = getFactory();

2. create a new participant with the help of the factory newResource call and with a new value for the primary key. After that update all the required fields for your asset.

  const newParticipant = factory.newResource(namespace, 'ParticipantName', <primkey>);
  newParticipant.RequiredField1 = value1;
  newParticipant.RequiredField2 = value2;
    ...

3.  Get an participant registry to update your participant:

  const newParticipantRegistry = await getParticipantRegistry( 
      namespace + '.ParticipantName');

4.  add the new participant to the participant registry.

   await newParticipantRegistry.add(newParticipant);