...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Saturday, July 7, 2018

Fabric composer tips and tricks - update assets or participants


To update an asset in Fabric composer in the transaction, you have to do the following steps:

0. Supposing you have a model file and an asset:

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

1. get a reference  to you asset. the reference usually comes from the input parameter, or following the object-graph of your input parameter. Optionally, you can query the asset registry for a certain asset or a set of assets. Having the reference, update the required fields.

  assetReference.RequiredField1 = newValue1;
  assetReference.RequiredField2 = newValue2;
    ...


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

  const factory = getFactory();


3.  Get an asset registry to update your asset:

  const assetRegistry = await getAssetRegistry(namespace + 
    '.AssetName');

4.  add the new asset to the asset registry.

   await assetRegistry .update(assetReference);

optionally, you can update several references parallel.

   await assetRegistry.updateAll(assetReferences);

The participant case is similar, the only difference is that instead of the asset registry you should use the participant regisrtry.