Consuming & Preconsuming Choice

HI All,

Contract Consumption

If no qualifier is present, choices are consuming: the contract is archived before the evaluation of the choice body and both the controllers and all contract stakeholders see all consequences of the action.

Preconsuming Choices

  • preconsuming keyword. Optional.
  • Makes a choice pre-consuming: the contract is archived before the body of the exercise is executed.
  • The create arguments of the contract can still be used in the body of the exercise, but cannot be fetched by its contract id.
  • The archival behavior is analogous to the consuming default behavior.
  • Only the controllers and signatories of the contract see all consequences of the action. Other stakeholders merely see an archive action.
  • Can be thought as a non-consuming choice that implicitly archives the contract before anything else happens

Kind of curious, what does “consequences of action” mean ? And what is the main difference between this too.

Reference: Choices

Thank you!

The consequences are the child nodes, i.e., the things you do in the body of your exercise node. The definition of this is in the ledger model. In that example, the consequences of the Accept exercise are the Transfer and the creation of the PaintAgree contract. You can also see these transaction structures in Daml studio in the transaction view.

A pre-consuming choice is syntactic sugar for a non-consuming choice that calls archive self at the beginning. For a pre-consuming choice, observers see only the call to archive but not the choice itself or any of its other consequences. For a consuming choice, observers see the choice and all of its consequences. Together with that the resulting transaction structures look slightly different, the transaction view in Daml studio can be useful for exploring this.

1 Like