Passing contract Key in a choice?

Can the key of a contract be passed to another contract through a choice?

...
        nonconsuming choice InviteNewParticipant : ContractId PoolInvite
            with
                inviter: Party
                newParticipant: Party
            controller owner, participants
            do
                create PoolInvite with
                    inviter = inviter
                    poolKey = this.key -- <----?????????
                    newParticipant = newParticipant
...

My concept was: Can you pass the key so you can have non-consuming choices, allowing for multiple Invites to be created in parallel? In the ExpensePool example, we have a Pool that transforms into a PoolInvite. Pool invites must be done one at a time. But by passing the key, could we generate all of the invites at once, and then have new participants accept each invite one at a time, and update the pool?

I think this drives into my similar question in https://discuss.daml.com/t/common-patterns-or-anti-for-data-vs-contracts/4530/4: If you wanted the ability for multiple participants to be accepted into the pool simultaneously, it would seem you need to use contracts per Pool-Invitee, and then fetch all of the accepted pool invitee contracts to find who are the participants of the pool?

Thanks

Yes. You want to use key as a function here, so key this in your example.

@Stephen thanks. Where is this fuction usage documented ?

Assuming it is this:

https://docs.daml.com/daml/stdlib/Prelude.html#function-da-internal-template-functions-key-44978

1 Like