0

我想检查 DAML 代码中的一个条件,但一个值是一方,另一个是文本,因此出现错误:

• 无法将类型“Party”与“Text”匹配,这是由于以下之间的功能依赖关系:使用“DA.Internal.Record.getField”实例而产生的约束“DA.Internal.Record.HasField“owner”AccountInfo Text” 'DA.Internal.Record.HasField“所有者”AccountInfo 方'在

if( login.party == "friend" || logout.party == "friend)
   userCId <- create Users with userType= "Friendly User",..
                            return (Right  userCId)
4

2 回答 2

6

正如 Shayne 所提到的,您可以使用show(或partyToText)转换为Text. 但是,我认为这不是解决此问题的正确方法。各方应被视为抽象标识符,而 DAML 沙箱允许您使用任意字符串,但对于其他分类帐而言并非如此。

我建议不要对特定方文字的检查进行硬编码,而是使用附加字段扩展模板,friend : Party然后与之进行比较。然后,当您创建模板时,您可以在沙盒上设置friend"friend"但您也可以将其设置为其他内容。

所以最后你最终更换

template C with
  …
  choice C : ()
    controller …
    do if login.party == "friend"
       …

与以下

template C with
  …
  friend : Party
  choice C : ()
    controller …
    do if login.party == friend
       …
于 2020-01-12T16:41:00.727 回答
-2

呼吁show您的Party价值应该可以解决问题。

if show login.party == "friend" ...
于 2020-01-12T13:15:13.187 回答