T.dedupCreate, parse Error


Full Code, I get an error with the T.dedupCreate portion, and I can’t seem to figure out why. Any ideas? I can’t tell if its an indentation issue, or if I’m using T.dedupCreate incorrectly.

also the documentation, below, doesn’t specify where I’m supposed to place the arguments of a choice? or am I misreading this.

dedupCreate : (Eq t, Template t) => t → TriggerA ()
Create the template if it’s not already in the list of commands in flight (it will still be created if
it is in the ACS).
Note that this will send the create as a single-command transaction. If you need to send multiple command

acceptSwapTrigger: T.Trigger ()
acceptSwapTrigger = T.Trigger 
 { initialize = pure (),
  updateState = \_  -> pure (),
  registeredTemplates = T.RegisteredTemplates [T.registeredTemplate @Trade, T.registeredTemplate @AssetHoldingAccount, T.registeredTemplate @TransferPreApproval],
  rule = \p -> do
    tradeRequests <- T.query @Trade
    let isMe = (\tradeRequests -> tradeRequests.receiver == p)
    let meList = filter (\(_, contract) -> isMe contract) tradeRequests

    debug ("asset holding account invites", meList)

    
    unless ( DA.Foldable.null meList ) do 
      case meList of 
        [] -> pure ()

        (cid, c) :: _ -> do
          optOfferedAsset <- T.queryContractId c.offeredAssetCid
          transferPreApproval <- T.queryContractId c.requestedAssetsTxPreApprovalCid
          whenSome optOfferedAsset $ \m -> do
            asset <- T.dedupCreate @Asset with 
              assetType = transferPreApproval.asset.assetType, 
              amount = transferPreApproval.asset.amount, 
              owner = p 
            txApproval <- T.dedupExerciseByKey @AssetHoldingAccount (m.asset.assetType, p) Preapprove_Transfer_In with asset = m.asset
            T.dedupExercise c Trade_Settle with 
              requestedAssetCid = asset
              offeredTxPreApprovalCid = txApproval


      
    debug $ "TRIGGERED",
  heartbeat = None
}

dedupCreate accepts the contract argument and then sends a command to create that contract. You are specifying the type (via @Asset) but you’re missing the constructor of the record (which is not prefixed with @).

T.dedupCreate @Asset Asset with
  assetType = …
  amount = …
  owner = …

should do the trick. However, the type argument can be inferred so you can also omit it and shorten it to

T.dedupCreate Asset with
  assetType = …

As for your question on choice arguments, dedupCreate does not exercise a choice so there is no choice argument. If you want to exercise a choice look at exerciseCmd and dedupExercise.

Thanks for the response!

I also know what i’m doing here below is wrong.
What I want to do is either create the contract, and capture the value, and use it as an argument later.

Or exercise a choice, and capture the return value, and use that as an argument. However, T.dedupeCreate, or T.ExerciseByKey both don’t return a value.

Does exerciseCmd work in a trigger? That seems to only work in Daml scripts?
asset <- T.dedupCreate @Asset with assetType = transferPreApproval.asset.assetType, amount = transferPreApproval.asset.amount, owner = p txApproval <- T.dedupExerciseByKey @AssetHoldingAccount (m.asset.assetType, p) Preapprove_Transfer_In with asset = m.asset T.dedupExercise c Trade_Settle with requestedAssetCid = asset offeredTxPreApprovalCid = txApproval


And why are these argument fields “ambiguous” now…

What I want to do is either create the contract, and capture the value, and use it as an argument later.

Or exercise a choice, and capture the return value, and use that as an argument.

You say you want to do either or but your current code does both. In which case do you want to create and in which case do you want to exercise?

However, T.dedupeCreate, or T.ExerciseByKey both don’t return a value.

Command submissions in triggers are always asynchronous so you don’t get a result. However, you can observe the effect of submitting the transaction later as part of a change to the ACS, e.g., if you submit a create the contract will be in the ACS later (assuming it succeeded). What return value are you looking for?

And why are these argument fields “ambiguous” now…

That error often happens if the type has no field with that value. Can you share the definition of Asset?

Does exerciseCmd work in a trigger? That seems to only work in Daml scripts?

You can use exerciseCmd in the list of commands you pass to emitCommands. But it’s a case of either use dedupExercise or use emitCommands + exerciseCmd not both.

1 Like