Daml Finance interfaces
- eriktimOP 1
Trying to grasp the concepts of Daml interfaces and its usage in Daml Finance.
One of the things I noticed that for some interfaces, theViewtype exposes data that is only used by the implementation, not the interface. I understand anyone fetching that interface contract would get access to the data as well, but in some cases I am confused on whether that is desired.To give a concrete example, please look at the interface NumericObservable and an implementation
Observation.Viewcontainsobservations, being aMap Time Decimal, but it also defines a non-consuming choiceObserve, which seems to contain the logic of observing thoseobservationsat some timet. Now what would be the rationale to expose theobservationsin the view in this case? - Matteo_Limberto 1
Hi @eriktim,
Thanks for your question.
A rationale for exposing data in the
viewis for e.g. displaying purposes in a template-agnostic UI. Your UI would work only against the interface type rather than the concrete template type.In the specific case of
NumericObservable, however, it is indeed undesirable to expose theobservationsin theview, as that would prevent us from defining additional observation templates such as the below. We will rectify this in an upcoming Daml Finance version.Thanks,
Matteo-- | Observe 1.0 if a credit event has happened, 0.0 otherwise template CreditEventObservation with provider : Party -- ^ The reference data provider. id : Id -- ^ A textual identifier. creditEventTime : Optional Time -- ^ Identifies when a credit event has happened. observers : PartiesMap -- ^ Observers. where signatory provider observer Disclosure.flattenObservers observers interface instance NumericObservable.I for CreditEventObservation where observe t = case creditEventTime of Some s | t >= s -> pure 1.0 _ -> pure 0.0 - eriktim
Ah in that sense the name
Viewfits nicely as well
Thanks for the clear explanation, @Matteo_Limberto!