Hi, I’m trying to use a mutable flag template (create/archived by bigUser) to control what another relatively immutable template can do (I prefer not to put the flag on TestLookup
as this can happen frequently).
I want smolUser to be able to call the ChangeUserIfNoFlag
function, while being permissioned by a mutable flag set by bigUser. I’m not sure which maintainer to use as visibleByKey
seem to require authorization by bigUser. What’s the best way to achieve this?
module Test.TestLookup where
import Daml.Script
template LookupFlag
with
bigUser: Party
smolUser: Party
smolUserId: Text
where
signatory bigUser
observer smolUser
key (bigUser, smolUser): (Party, Party)
maintainer [key._1]
template TestLookup
with
bigUser: Party
smolUser: Party
smolUserId: Text
where
signatory smolUser
observer bigUser
choice ChangeUserIfNoFlag
: ContractId TestLookup
with
newSmol : Party
newSmolId : Text
controller smolUser
do
isDisabled <- visibleByKey @LookupFlag (bigUser, smolUser)
assertMsg "Disabled by bigUser" (not isDisabled)
create this with
smolUser = newSmol
smolUserId = newSmolId
testChangeLookup = do
big <- allocateParty "BIG"
smol1 <- allocateParty "SMOL1"
smol2 <- allocateParty "SMOL2"
testLookupCid <- submit smol1 do
createCmd TestLookup with
bigUser = big
smolUser = smol1
smolUserId = "user1"
smol2LookupCid <- submit smol1 do
exerciseCmd testLookupCid ChangeUserIfNoFlag with
newSmol = smol2
newSmolId = "user2"
pure ()