Let me see if I understand your requirements here. You have a predefined token, and a bunch of parties who are expecting a contract with that token as the key. In your ideal world, the key for the contract would be just that token, and everyone interested (among the authorized parties) could retrieve the contract using that token, with no regard for who created said contract.
But DAML gets in your way because it requires the key to contain a Party, and using the creator of the contract as the party here makes the contract impossible to find.
We can’t get around the fact that a key needs a maintainer — @bernhard can explain the reasons better than I, but it essentially boils down to the fact that we’re in a distributed system so we need to have someone we can ask for the contract with that key.
One option here would be to have a “central” authority, i.e. a party whose job is to publish the tokens and sign the contracts; perhaps something like:
module Main where
import Daml.Script
template Registry
with
clients: [Party]
operator: Party
where
signatory operator
observer clients
nonconsuming choice CreateTopic : ()
with
proposer: Party
token: Text
controller proposer
do
assert $ proposer `elem` clients
create Topic with token, proposer, observers = clients, operator
return ()
template Topic
with
token: Text
proposer: Party
observers : [Party]
operator: Party
where
signatory operator
observer observers
key (operator, token) : (Party, Text)
maintainer key._1
nonconsuming choice Demo : ()
with
p: Party
controller p
do return ()
test = script do
alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
charlie <- allocatePartyWithHint "Charlie" (PartyIdHint "Charlie")
reg <- submit alice do
createCmd Registry with clients = [alice, bob, charlie], operator = alice
submit bob do
exerciseCmd reg $ CreateTopic with proposer = bob, token = "blabla"
submit charlie do
exerciseByKeyCmd @Topic (alice, "blabla") Demo with p = charlie
return ()
So the maintainer is always the same and you don’t need to pass it around.