Skip to content
CCPEDIAby Unity Nodes
App Development

Conditionally consuming choice

5 posts535 views12 likesLast activity Jul 2020

  1. dliakakosOP 3

    Can DAML allow for a choice to be consuming based on a condition in the body of the choice?

    (I am aware that this is not supported but I am more curious if it is just a missing feature or there is a deeper reason behind having to declare a choice consuming (or not) a priori.

    Consider this example:

    template Foo
      with
        party : Party
      where
        signatory party
    
        controller party can
          MaybeConsume : ContractId Foo
            with
              conditionToConsume : Bool
            do
              if conditionToConsume
              then create this  -- consume and recreate
              else return self  -- don't consume
    
  2. cocreature 5

    Are you specifically looking for something that has the same privacy implications as a consuming choice? If not, you can use a nonconsuming choice + archive self, e.g., taking your example:

    template Foo
      with
        party : Party
      where
        signatory party
    
        nonconsuming choice MaybeConsume : ContractId Foo
            with
              conditionToConsume : Bool
            controller party
           do if conditionToConsume
                  then do archive self
                          create this
                  else pure self
    
    
  3. dliakakos

    nice! hadn’t thought of that - thank you. What do you mean by same privacy implications?

  4. cocreature 1

    A non-consuming exercise is only visible to signatories and the actor. A consuming exercise on the other hand is visible to all stakeholders and actors so it is also visible to observers. IME, the behavior of non-consuming choices is often what you actually want so it’s not that uncommon to use a non-consuming choice and archive self to get this. You can also use preconsuming and postconsuming choices which desugar to a non-consuming choice with the archive self at the beginning or end.

  5. Gary_Verhaegen 3

    Just a note that, should the choice archive the contract, observers on that contract still see the archive itself, though they don’t see the non-consuming choice execution or its other consequences.

    This is all documented here.