像在对象中一样访问 YAML 模板中的变量

Acess variables in DAML template like in an object

好的,我是 DAML 的新手,具有丰富的 Java 编程经验。现在,我有一个问题。在Java中,'Class A'有'Class B',这样,A可以用'Class B'的'state'。我也想在 DAML 中做这样的事情。

如果我认为模板是一个class,'contract id'是它的一个实例,而模板的'state'(我们在'with'中声明的东西)当作为参数传入时,应该可以在另一个模板中访问,但我在编写的代码中遇到编译错误。

一种继续进行的方法是发送 'party' 作为参数而不是合同 ID,然后尝试访问合同中的一方,但我想检查这是否/有什么问题!

提前致谢!

第一个模板

daml 1.2
module RFP where

template RFP
with
        requestorCEO: Party
    where
        signatory requestorCEO

第二个模板

daml 1.2

module InternalComm where

import RFP

template InternalComm 
    with
        -- RFP is sent in as a parameter to this template.
        rfpContractID: ContractId RFP
    where
        -- Here with this, I'm trying to say that the CEO who would be approving 
        -- an RFP is the signatory for internal communications too. It is the
        -- below line that fails with compilation error.
        signatory rfpContractID.requestorCEO

这是我针对上述问题收到的实际错误消息。如有任何想法,我们将不胜感激!

No instance for (DA.Internal.Record.HasField
                         "requestorCEO" (ContractId RFP) a0)

在 DAML 中,RFP 模板为您提供了一个类型 RFP,您可以在其上投影字段(就像 Java),以及一个类型 ContractId RFP,它更像是一个指向账本上合约的指针。您可以 "dereference" ContractId 使用函数 fetch 获得 RFP。但是,该函数在 Update 中运行,因此不能从 signatory 中调用。我怀疑您需要更改 InternalComm 以采用没有 ContractId 包装器的 RFP

这就是它的工作原理 - 只需从整个模板中删除 ContractId。

module InternalComm where

import RFP

template InternalComm 
    with
        -- ContractId to be removed from below line, and compilation error is resolved.
        -- rfpContractID: ContractId RFP
        rfpContractID: RFP
    where
        signatory rfpContractID.requestorCEO