0

在 DAML 中,我可以在合约 A 中保存 B 的 contractId 吗?我尝试了以下操作,但创建合同会返回更新,我无法将该更新保存在任何地方,甚至无法访问其数据。


template OneContract
  with
    someParty : Party
    someText : Text
    someNumber : Int  
  where
    signatory someParty



template Main
  with
    anyone :  Party
    cid : ContractId OneContract
  where
    signatory anyone

    controller anyone can
      nonconsuming CreateOneContracts : ()
        with 
          p : Party
          int : Int
        do
-- cid is not bind to cid in the contract
          cid <- create OneContract with someParty = p, someText = "same", 
someNumber = int
-- let won't work since create returns an update 
          let x = create OneContract with someParty = p, someText = "same", 
someNumber = int
          pure()

4

1 回答 1

1

您对 的想法是正确的cid <- ...,但这将创建一个新的局部变量cid,其中包含合同 ID。DAML 中的所有数据都是不可变的,这意味着您不能写入this.cid. 您必须存档合同并重新创建它以更改存储在其上的数据:

template Main
  with
    anyone :  Party
    cid : ContractId OneContract
  where
    signatory anyone

    controller anyone can
      CreateOneContracts : ContractId Main
        with 
          p : Party
          int : Int
        do
          newCid <- create OneContract with someParty = p, someText = "same", someNumber = int
          create this with cid = newCid

请注意,这仅适用于anyone == pp创建 a 需要 的权限OneContract with someParty = p,并且在选择的上下文中唯一可用的权限CreateOneContracts是 of anyone

于 2019-06-04T06:31:39.097 回答