Is there a way to assert in a script that a contract has (or has not) been divulged to a party?
For example, what would I add to the sample code to confirm that the secret was divulged to player?
sample code
module Example where
import Daml.Script
import DA.Assert
template Secret
with
owner : Party
secret : Int
where
signatory owner
template Game
with
owner : Party
player : Party
where
signatory owner, player
nonconsuming choice Divulge : ()
with secretId : ContractId Secret
controller owner
do _ <- fetch secretId
return ()
example = script do
owner <- allocateParty "owner"
player <- allocateParty "player"
secretId <- submit owner do createCmd Secret with secret = 42,..
game <- submitMulti [owner, player] [] do createCmd Game with ..
submit owner do exerciseCmd game Divulge with ..
-- note: does not really test for divulgence
sharedSecrets : [(ContractId Secret, Secret)] <- query player
sharedSecrets === []
return ()
1 Like
There isn’t a great way of doing that unfortunately. At this point you can try fetching it but that results in a warning since that behavior is deprecated. I think it’s the best you can do atm though:
template Fetcher
with
stakeholder : Party
fetcher : Party
where
signatory stakeholder
observer fetcher
nonconsuming choice FetchSecret : Secret
with
cid : ContractId Secret
controller fetcher
do fetch cid
example = script do
owner <- allocateParty "owner"
player <- allocateParty "player"
secretId <- submit owner do createCmd Secret with secret = 42,..
game <- submitMulti [owner, player] [] do createCmd Game with ..
cid <- submit owner $ createCmd (Fetcher owner player)
submitMustFail player $ exerciseCmd cid (FetchSecret secretId)
submit owner do exerciseCmd game Divulge with ..
submit player $ exerciseCmd cid (FetchSecret secretId)
return ()
Ideally you would test this by looking at the transaction tree stream of player
and seeing the fetch there but that also fails for two reasons:
- Daml Script does not yet expose transaction tree streams.
- Transaction tree streams omit fetches so you wouldn’t actually see it in there.
1 Like