My approach has been to add a new choice to the Workflow.Transfer.Request template along the lines of:
nonconsuming choice AddObserver : ContractId Request
with
newObserver : Party
controller receiverAccount.owner
do
(accountCid, _) <- fetchByKey @Account.I receiverAccount
let disclosureCid = toInterfaceContractId accountCid
-- call AddObservers choice on Disclosure using exerciseInterfaceByKey
pure this
However this doesn’t seem to be the right approach. My import of Disclosure:
import Daml.Finance.Interface.Util.Disclosure qualified as Disclosure (I)
fails as it is a member of a hidden package, and I am also not sure that fetchByKey is the correct way to go given that I want an interface Account and I’m not sure how to obtain this from the key. Thanks!
Thanks for your question, this is useful feedback.
The hidden package error can be resolved by adding Daml.Finance.Interface.Util as a data dependency in your daml.yaml file. You will also need to include it in the get-dependencies.sh script.
Coming to the actual disclosure logic, your approach does make sense: within the choice, you want to
fetch the AccountCid from its key
use toInterfaceContractId to cast to the Disclosure.I interface
exercise the AddObservers choice
Given that language support for interface keys is not there yet, we have written a helper function Account.exerciseInterfaceByKey that reproduces the above steps.
You will notice that the choice actor receiverAccount.owner is repeated twice:
the first input is used to fetch the account cid
the second input is used as input to the AddObservers choice
If you are interested in understanding more of the workaround that we used to get key support for interfaces, I tried to explain it here.
That said, your post made me realise that it might not be the best idea to expose new users to this sort of workaround. Hence I might discuss with the team if it makes sense to remove the temporary disclosure exercise until interface key support lands.
Thanks @Matteo_Limberto that worked. I did see exerciseInterfaceByKey but didn’t realise I could use it with the Disclosure interface in the above way. I see now that this makes sense!
I think the exercise is fine but maybe just needs a pointer or two for people new to this. Specifically I would say the two points you mentioned above: editing the get-dependencies.sh/daml.yaml and using exerciseInterfaceByKey.