Skip to content

Instantly share code, notes, and snippets.

@cocreature
Last active August 18, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocreature/c8dc3da0b869628d0f9e70aaf432bf00 to your computer and use it in GitHub Desktop.
Save cocreature/c8dc3da0b869628d0f9e70aaf432bf00 to your computer and use it in GitHub Desktop.
{-
-*- mode: haskell;-*-
-}
module FetchByKey where
template TKey
with
p : Party
where
signatory p
key p : Party
maintainer key
template Helper
with
p : Party
where
signatory p
choice FetchKey : (ContractId TKey, TKey)
with
k : Party
controller p
do fetchByKey @TKey k
template T
with
p1 : Party
p2 : Party
where
signatory p1
observer p2
nonconsuming choice C : (ContractId TKey, TKey)
with
k : Party
controller p2
do createAndExercise (Helper p1) (FetchKey k)
test = do
p1 <- getParty "p1"
p2 <- getParty "p2"
submit p1 (create (TKey p1))
submit p2 (create (TKey p2))
cid <- submit p1 (create (T p1 p2))
-- submitter p2 is not a stakeholder
submitMustFail p2 (exercise cid (C p1))
-- submitter p2 is a stakeholder but we only have authorization from p1
submitMustFail p2 (exercise cid (C p2))
pure ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment