Interface Cid vs Template Cid

Hi,

This question is around this implementation - daml-finance/src/main/daml/Daml/Finance/Interface/Util/KeyTable.daml at 484dcab2b66a5366636353bae351deae23b0b6f8 · digital-asset/daml-finance · GitHub

I saw in the docs (and here) that interfaces and templates have the same contract Id, does that imply that if we store the interface cid on a template, and the template cid that the interface was converted from changes (archived and recreated), trying to use the original interface cid to convert back to a template would fail?

The reason I am asking is for the HasSyntheticKey class, we are getting the key from an interface contract id. So, if the above is true where the conversion back to a template would fail that would mean that on every archival/creation of a contract we would have to update the instance for HasSyntheticKey? Or, we instead just use the getKey function?

Thanks,

Austin

Hi Austin,

Yes, that’s right.

The HasSyntheticKey type-class is used to assign a stable identifier (i.e. a key) to an interface contract.

The getKey method takes an interface value (not an interface contract id) and extracts the key. To that end, it is a pure function and does not need to change should the contract id change.

The map from synthetic key to contract id is tracked in the KeyTable data structure.

When executing a choice, changes to contracts (e.g. an archive and re-create) must be reflected in the KeyTable (using the insert and delete methods).