如何在 DAML 中将 Map 的键作为观察者提及?

How to mention keys of a Map as observers in DAML?

我想在我的合同模板中使用(Party,CustomObj)的地图作为 attribute/argument。我还想在合同模板中将密钥列表指定为观察者。 我怎样才能做到这一点?

谢谢。

observer 接受范围内带有模板参数的任意表达式。因此,您可以编写一个从地图中提取键的表达式。为此,首先转换为 (key, value) 对列表,然后使用 map fst 丢弃值。这是一个完整的例子:

module Main where

import DA.Next.Map (Map)
import qualified DA.Next.Map as Map

data CustomObj = CustomObj
  deriving (Eq, Show)

template T
  with
    sig : Party
    m : Map Party CustomObj
  where
    signatory sig
    observer map fst (Map.toList m)