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

Sunday, April 29, 2018

Generating Solidity from Hyperledger Fabric Composer: related assets

One of the idea of Hyperledger Fabric Composer is to have a domain specific language to model complex assets. Besides properties of an asset, connections or relations between assets can be defined as well. Like considering the following example:

asset TestAsset identified by primaryKey{
  o String primaryKey
  o String property1
  o String property2
  --> RelatedAsset relatedAsset
}

asset RelatedAsset{
}

The structure can be translated into several smart-contracts that reference to each other like in the following example:

contract RelatedAsset{
}

contract  TestAsset{
  string primaryKey;
  string property1;
  string property2;
  RelatedAsset public relatedAsset;
  
  function setRelatedAsset(RelatedAsset _relatedAsset) {
      relatedAsset = _relatedAsset;
  }
}

Certainly it is an open question how these contracts are created. On way is that there is an external factory contract that creates and administrates such a creation and calls only the setRelatedAsset function. Another way might be that the contracts realize the CRUD (Create Read Update Delete) operations on their own. 

A totally different way might be to use structs instead of contracts which makes things certainly much cheaper from a gas consumption perspective, however all CRUD operations must be handled externally.

contract Factory{

    struct RelatedAsset{
    }

    struct  TestAsset{
        string primaryKey;
        string property1;
        string property2;
        RelatedAsset  relatedAsset;
    }
}