diff --git a/compiler/damlc/daml-stdlib-src/DA/Internal/Template.daml b/compiler/damlc/daml-stdlib-src/DA/Internal/Template.daml index 75650e1f24f..9823a1a0f54 100644 --- a/compiler/damlc/daml-stdlib-src/DA/Internal/Template.daml +++ b/compiler/damlc/daml-stdlib-src/DA/Internal/Template.daml @@ -110,6 +110,12 @@ exerciseByKey k c = do (cid, _) <- fetchByKey @t k exercise cid c +-- | Create a contract and exercise the choice on the newly created contract. +createAndExercise : forall t k c r. Choice t c r => t -> c -> Update r +createAndExercise t c = do + cid <- create t + exercise cid c + data NonConsuming t = NonConsuming {} data PreConsuming t = PreConsuming {} data PostConsuming t = PostConsuming {} diff --git a/compiler/damlc/tests/daml-test-files/CreateAndExercise.daml b/compiler/damlc/tests/daml-test-files/CreateAndExercise.daml new file mode 100644 index 00000000000..bb326826c10 --- /dev/null +++ b/compiler/damlc/tests/daml-test-files/CreateAndExercise.daml @@ -0,0 +1,20 @@ +-- Copyright (c) 2019, Digital Asset (Switzerland) GmbH and/or its affiliates. +-- All rights reserved. + +daml 1.2 module CreateAndExercise where + +import DA.Assert + +template T1 + with + p : Party + where + signatory p + choice C1 : Int + controller p + do pure 42 + +main = scenario do + alice <- getParty "Alice" + r <- alice `submit` createAndExercise (T1 alice) C1 + r === 42 diff --git a/unreleased.rst b/unreleased.rst index 93ccbb742ce..13756599df9 100644 --- a/unreleased.rst +++ b/unreleased.rst @@ -34,3 +34,4 @@ HEAD — ongoing - `com.digitalasset.daml-lf-archive` becomes `com.digitalasset:daml-lf-dev-archive-java-proto` - `com.digitalasset.daml-lf-archive-scala` becomes `com.digitalasset.daml-lf-archive-reader` -[Sandbox] Filter contracts or contracts keys in the database query for parties that cannot see them. ++ [DAML Standard Library] Add ``createAndExercise``