1

我有 2 个关于 DAML 自动选择和场景的可能性的问题。我有这个模板需要输入 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

我需要在场景中创建其中一些模板,但无法指定 ContractId(如 #0:0),这给了我以下错误:Couldn't match expected type 'ContractId Observers' with actual type 'Text'是否可以在场景中指定 ContractId?

接下来,在上面的模板中,我有一个choice定义的调用Load_all_creation_observers,它创建一个模板 Creation 并将指定的观察者加载template 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

就目前的代码而言,当用户创建一个模板时,Create_Creation template他需要执行Load_all_creation_observers选择以创建Creation模板,并将所有观察者加载到模板中。Create_Creation当用户提交模板时,是否可以自动执行此选择?或者可能根本不选择它并将其定义为自动化功能,就像您在普通编程语言(if 语句)中所做的那样。您似乎只能do在选择中定义功能。

4

2 回答 2

2

鉴于有关合同 ID 的问题已经得到解答,我将专注于您的第二个问题。

您不能自动执行选择(您可以有一些账本外自动化,例如执行此操作的 DAML 触发器,但在这种情况下您无法获得任何原子性保证)。我解决这个问题的方法是定义一个带有单个选项的新模板,然后CreateAndExercise在分类帐 API 上调用该选项。这几乎等同于定义一个顶级函数。对于您的示例,这将类似于以下内容

template CreateCreationTemplate
  with
    p : Party
  where
   signatory p
   choice CreateCreation : ContractId Creation
     with
      observers_list_id : ContractId Observers
      artist : Party
      title : Text
      votingRight : Set Party
     do observers_list <- fetch observers_list_id
        create Creation with
          created_by = p
          artist = artist
          title = title
          votingRight = votingRight
          observers_list_id = observers_list_id
          observers = observers_list.observers

您可以将一些选择的字段作为模板的字段,但作为一般准则,在模拟顶级函数时,我倾向于只将派对作为模板的字段。

根据您的使用情况,也可以有一个带有非消耗CreateCreation选项的“工厂”模板。

于 2020-03-09T09:51:24.343 回答
1

在一个场景中,账本上唯一存在的合同是迄今为止在该场景中创建的合同。因此,如果有一个ObserverscontractId,则Observers必须在场景中的某个先前时间点创建了一个合同。

ContractIds 是不透明的并且绝对不可预测,所以考虑一个 contract-id 文字是没有意义的。相反,在创建合约时,在该点绑定生成的 id。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
于 2020-03-09T01:27:54.700 回答