Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add archiveCmd to DAML Script #7268

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add archiveCmd to DAML Script
Factored out from #7264 and added a test. Just makes the migration a
tiny bit easier.

changelog_begin

- [DAML Script] Add `archiveCmd cid` as a convenience wrapper around
`exerciseCmd cid Archive`.

changelog_end
  • Loading branch information
cocreature committed Aug 31, 2020
commit 654a1876f70d7b8ab452b76c78662464818a4cf9
10 changes: 8 additions & 2 deletions compiler/damlc/tests/src/DA/Test/ScriptService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ main =
"testMulti = do",
" p <- allocateParty \"p\"",
" (cid1, cid2) <- submit p $ (,) <$> createCmd (T p 23) <*> createCmd (T p 42)",
" submit p $ (,) <$> exerciseCmd cid1 C <*> exerciseCmd cid2 C"
" submit p $ (,) <$> exerciseCmd cid1 C <*> exerciseCmd cid2 C",
"testArchive = do",
" p <- allocateParty \"p\"",
" cid <- submit p (createCmd (T p 42))",
" submit p (archiveCmd cid)"
]
expectScriptSuccess rs (vr "testCreate") $ \r ->
matchRegex r "Active contracts: #0:0\n\nReturn value: #0:0\n\n$"
Expand All @@ -121,7 +125,9 @@ main =
" DA\\.Types:Tuple2@[a-z0-9]+ with",
" _1 = 23; _2 = 42",
""
],
]
expectScriptSuccess rs (vr "testArchive") $ \r ->
matchRegex r "'p' exercises Archive on #0:0",
testCase "exerciseByKeyCmd" $ do
rs <-
runScripts
Expand Down
7 changes: 7 additions & 0 deletions daml-script/daml/Daml/Script.daml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Daml.Script
, exerciseCmd
, exerciseByKeyCmd
, createAndExerciseCmd
, archiveCmd
, getTime
, setTime
, sleep
Expand Down Expand Up @@ -287,6 +288,12 @@ exerciseByKeyCmd key arg = Commands $ Ap (\f -> f (ExerciseByKey (templateTypeRe
createAndExerciseCmd : forall t c r. Choice t c r => t -> c -> Commands r
createAndExerciseCmd tplArg choiceArg = Commands $ Ap (\f -> f (CreateAndExercise (toAnyTemplate tplArg) (toAnyChoice @t choiceArg) identity) (pure fromLedgerValue))

-- | Archive the given contract.
--
-- `archiveCmd cid` is equivalent to `exerciseCmd cid Archive`.
archiveCmd : Choice t Archive () => ContractId t -> Commands ()
archiveCmd cid = exerciseCmd cid Archive

instance Applicative Script where
pure a = Script $ \ s -> return (a, s)

Expand Down