0

好的,我是 DAML 新手,拥有丰富的 Java 编程经验。现在,我有一个问题。在 Java 中,“A 类”有“B 类”,这样,A 可以使用“B 类”的“状态”。我也想在 DAML 中做这样的事情。

如果我认为模板是一个类,'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)
4

2 回答 2

1

在 DAML 中,RFP 模板为您提供了一种类型RFP,您可以在该类型上投射字段(就像 Java 一样),以及一种ContractId RFP更像是指向账本上合约的指针的类型。您可以“取消引用”ContractIdRFP使用该功能fetch。但是,该函数在 中运行Update,因此不能从 中调用signatory。我怀疑您需要更改InternalCommRFP不使用ContractId包装器。

于 2019-06-29T10:23:59.290 回答
0

这就是它的工作原理 - 只需从整个模板中删除 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

于 2019-07-01T07:27:11.537 回答