Is interface View a read-only dataset?

What are the ethics for defining attributes of Interface View? Should the parameters being passed during contract creation be passed on to the interface view? Are they read-only, and what happens when we archive a contract? If not, how do I update a view from within a contract instance.

module Daml.Grants.Interface.Workflow.Processes.PreAwardProcess where
-- | View for `Process`.
data View = View
  with
    state : PreAwardPhaseState  
       -- ^ Internal state of the workflow process.
    generalReviewerTask : ContractId Task.I  
       -- ^ The task assigned to the party reviewing the grant opportunity.      
    technicalReviewer : ContractId Task.I  
       -- ^ The task assigned to the party providing the technical review of the grant opportunity.      
    financialReviewer : ContractId Task.I  
       -- ^ The task assigned to the party providing the financial review of the grant opportunity.      
  deriving (Eq, Show)
...
...
...

-- | An interface to implement pre-award process
interface Process where
  viewtype V
...
...
...

-- | A representation of process object
template PreAwardProcess
  with
    processKey : ProcessKey
      -- ^ Unique identifier for the process.
    grantOpportunityCid : ContractId GrantOpportunity.I
      -- ^ An identifier of the grant opportunity.
    grantApplicationCid : ContractId GrantApplication.I
      -- ^ An identifier of the grant application.
    state : PreAwardPhaseState  
       -- ^ Internal state of the workflow process.  
    observers : PartiesMap
      -- ^ The factory's observers
  where
...
...
...


Hi @code_monkey,

The view for an interface is derived from the implementing template’s attributes. You specify how to construct the view once you define your interface instance, e.g.,

interface instance Process for PreAwardProcess where
  view = View with state = state; generalReviewerTask = ...

As far as I understand, views are never stored on the ledger, they are just calculated from the implementing template. In this regard, they are just “projections” of a contract.

Contracts in Daml are immutable, which makes the view for an interface of a specific contract also immutable. In order to change e.g. the state in your code above, you need to archive the original PreAwardProcess contract and create a new one with an updated state. The view for the new contract will contain the updated state.

Hope this helps,
Matteo

2 Likes