I have 2 questions regarding DAML the possibility of automated choices and scenario.
I have this template that requires the input of a ContractId
:
template Create_Creation
with
current_login : Party
artist : Party
title : Text
votingRight : Set Party
observers_list_id : ContractId Observers
where
signatory current_login
I need to create some of these templates in scenario, but am unable to specify a ContractId (like #0:0), giving me errors such as: Couldn't match expected type 'ContractId Observers' with actual type 'Text'
Is it possible to specify a ContractId in scenario?
Next, in the above template I have a choice
defined called Load_all_creation_observers
that creates a template Creation and loads the observers specified in template Observers
into it as observers:
choice Load_all_creation_observers : ContractId Creation
controller current_login
do
observers_list <- fetch observers_list_id
create Creation with created_by = current_login; artist = artist; title = title;
votingRight = votingRight; observers_list_id = observers_list_id; observers = observers_list.observers
template Observers
with
superuser : Party
observers : Set Party
where
signatory superuser
observer observers
As the code stands now, when a user creates a Create_Creation template
he is required to perform the Load_all_creation_observers
choice to create the Creation
template with all the observers loaded into it. Is it possible to perform this choice automatically when a user submits the Create_Creation
template? or maybe not make it a choice at all and define it as automated functionality like you would do in normal programming languages (if statements). You can only seem to define do
functions in choices.
In a scenario, the only contracts that exist on the ledger are those that have been created thus far in that scenario. So if there is an Observers
contractId an Observers
contract must have been created at some previous point in the scenario.
ContractIds are opaque and definitely not predictable, so it makes no sense to think of a contract-id literal. Instead, when the contract is created, bind the resulting id at that point. Ie.
test = scenario do
su <- getParty "Super User"
obsId <- su submit create Observers with ...
p1 <- getParty "Party 1"
ccId <- p1 submit create Create_Creation with ...; observers_list_id = obsId