Can somebody explain the gibberish in this paragraph?
– Type synonym for Reference. This type is currently used as a work-around given the lack of interface keys.
type R = Reference
– HIDE
– This template is used to key an Account contract. It allows for looking up this contract|
– by key then acquiring the Account contract by fetching its contract id on this contract.|
– As updates are made to an Account, this Reference contract is required to be kept in sync.|
template Reference
An interface can be implemented by several templates. Each template can have a key type, but these types are independent of each other. So those keys cannot be used as an abstract means to look up contracts of templates that implement interface Account.
It is worth noting that ContractId Account is an interface contract ID, and the key of the contract it references is of indeterminate type and structure. Reference effectively unifies them as follows:
contract maps to interface view for Account, View, no matter its template
View maps to AccountKey
that is the template key type for Reference
The idea of interface keys is not trivial, either design-wise or implementation-wise, and so it isn’t available in the current interfaces alpha.
Thanks for your question. Let me try to clarify why we use the Reference workaround. I assume here that you are familiar with contract keys (which apply to templates and are documented here).
In Daml Finance we work with interfaces and, as Stephen mentions, Account is in this case an interface type, for which in principle multiple template implementations can exist.
We wanted a way to reference an Account by key, but interface keys are not currently supported: for interfaces we can only use ContractIds.
Hence the following workaround:
define a concrete template called Reference which is keyed (with a contract key)
have Reference store the ContractId of an Account
We then define some helper functions called exerciseInterfaceByKey which effectively
fetch the Reference contract by key
exercise a choice on the corresponding Account contract using the ContractId that is stored in the Reference
Hopefully we will be able to remove this workaround once interface keys are supported.