digital-asset / daml-finance

Apache License 2.0
17 stars 16 forks source link

'unflatten' keys in core models #1167

Open lucianojoublanc-da opened 7 months ago

lucianojoublanc-da commented 7 months ago

Templates and Interfaces such as Account are currently 'flat', meaning they have no nested structures:

data View = View
  with
    custodian : Party
      -- ^ Party providing accounting services.
    owner : Party
      -- ^ Party owning this account.
    id : Id
      -- ^ Identifier for the account.
    description : Text
      -- ^ Human readable description of the account.
    controllers : Controllers
      -- ^ Parties controlling transfers.

Accessing the keys of these entities can be done with a convenience function, e.g. toKey in this case:

-- | Convert the account's 'View' to its key.
toKey : View -> AccountKey
toKey v = AccountKey with custodian = v.custodian; owner = v.owner; id = v.id

While this works fine within Daml, these functions can't be used from a client application. These need to be packed/unpacked manually, (both externally, but also in Daml) - which requires looking at the function definition to know what the key is.

I suggest that this be changed to:

data View = View
  with
    key: AccountKey
    description : Text
      -- ^ Human readable description of the account.
    controllers : Controllers
      -- ^ Parties controlling transfers.

I have a recollection that at some point we had this, and I think it's changed since.

lucianojoublanc-da commented 7 months ago

Note that this is also inconsistent: for Holding for example, we have InstrumentKey and AccountKey on the contract.