Right, so there are two different issues here, and I got confused.
On the one hand, there is the question of how does Bob, the “person” behind the Party and the entity sending gRPC requests to create contracts and execute choices, know about contracts they’re an observer on.
On the other hand, there is the question of how, from Daml code, the bob
party can fetch a contract by key when they are a non-signatory observer of said contract.
Hopefully my previous message answers the second question, so I’ll focus on the first one now. But please do not hesitate to ask follow-up questions on both.
As an entity interacting with the ledger, Bob needs to be using the gRPC API. (For our purposes here, the HTTP JSON API, if used, is transparent.) The gRPC API, broadly speaking, lets Bob do two things:
- Act on the ledger: send Create and Exercise commands to “make things happen”, or, from another perspective, “record” things on the ledger.
- Subscribe to the ledger to get notified when other people do things.
That second point is very important. The ledger is a synchronization point between multiple parties and, when you create a contract, you do want to know when someone else exercises a choice on your contracts. Similarly, you also want to know when someone else creates a contract you’re an observer on.
The Script
mechanics you can use in the IDE accurately reflects point 1, but sort of sidesteps point 2 completely. In a real Daml system, point 2 is essential and every entity involved with a given Daml ledger will be listening to ledger updates in some form.
Exactly how you subscribe to notifications will depend on what your program is and does, but any application (or UI, as in the getting started example app) that interacts with a Daml ledger will have some form of subscription to change notifications.