Conditionally consuming choice
- 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 - 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 - dliakakos
nice! hadn’t thought of that - thank you. What do you mean by same privacy implications?
- 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 selfto get this. You can also usepreconsumingandpostconsumingchoices which desugar to a non-consuming choice with thearchive selfat the beginning or end. - 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.