在 DAML 中是否可以使用类似地图的函数来迭代合同 ID 列表,检索它们并在每个上执行选择?这似乎在 DAML 中受到限制,因为在执行选择时,所有内容都需要包装在单个更新中。
这是我尝试过的一个示例(注意问题):
exerciseChoice: ContractId ContractB -> Update (ContractId ContractB)
exerciseChoice contractB = do (exercise contractB UpdateB with newText = "test")
template ContractA
with
party : Party
contracts: [ContractId ContractB]
where
signatory party
controller party can
nonconsuming UpdateA : [Update (ContractId ContractB)]
with newText : Text
do
-- a <- create ContractB with party = party; text = newText
-- a2 <- exerciseChoice a
-- return [a2] #these lines work fine
return map exerciseChoice contracts
-- #this doesn't work due to DAML implicitly adding Update before return definition
-- i.e. DAML expects type 'Update [Update (ContractId ContractB)]' based on this signature
-- we need a function which converts something like:
-- '[Update (ContractId ContractB)] -> Update [ContractId ContractB]'
template ContractB
with
party : Party
text: Text
where
signatory party
controller party can
UpdateB: ContractId ContractB
with newText: Text
do create this with text = newText
如果可以解决这个问题,您能否解释一下为什么在 DAML 中返回多个元组时,它们似乎隐式转换为 from (Update (ContractId A), Update (ContractId B))
to Update (ContractId A, ContractId B)
?