daml - DAML场景下,如何复用getParty?

标签 daml

我正在编写多个具有类似设置的场景:

test0 = scenario do
  bank <- getParty "Bank"
  alice <- getParty "Alice"
  -- ....
  assert True

test1 = scenario do
  bank <- getParty "Bank"
  alice <- getParty "Alice"
  -- ...
  assert True

linter 建议我减少重复:

 /Foo.daml:5:3: Suggestion: Reduce duplication
  Found:
  bank <- getParty "Bank"
  alice <- getParty "Alice"
  assert True
  Perhaps:
  Combine with /Users/shaynefletcher/Foo.daml:11:3

如何从场景中提取设置?

最佳答案

得到 Shayne F 的答复:

parties = do
  bank <- getParty "Bank"
  alice <- getParty "Alice"
  return (bank, alice)

test0 = scenario do
  (bank, alice) <- parties
  -- ....
  assert True

test1 = scenario do
  (bank, alice) <- parties
  -- ...
  assert True

为了清楚起见,各方的类型签名是:

parties : Scenario (Party, Party)

关于daml - DAML场景下,如何复用getParty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57926503/

相关文章:

daml - 在 'date' 语句或 'create' 语句内使用 'exercise' 函数时出现问题

typescript - 如何按时间倒序排列 create-daml-app 项目中的消息?

daml - 行使选择时如何获取当前合约id

java - 开始使用 Ledger API

daml - 通过 Java 或 JavaScript 以外的语言使用 DAML Ledger API

daml - 有没有一种方法可以尝试通过ID来获取契约(Contract),并且在契约(Contract)处于非事件状态时不会失败?

types - DAML 有对应的 Google 吗?

daml - 如何通过JSonApi从Daml中查询Map值?