Making contracts and parties visible to a party
Hi,
I have a situation where the operator party creates the network and on-boards a bunch of seller and buyer parties. I need the buyers to fetch / see all sellers (for the purposes of sending a Request for Quotation to one or more of them). How would I achieve that?
Many thanks!
There is the Fetch All Known Parties JSON API endpoint, but that is not exactly what you need:
https://docs.daml.com/json-api/index.html#fetch-all-known-parties
You can also create a non-consuming choice that returns all sellers that the party specified as the choice argument can deal with.
exerciseResult field on the response will contain the sellers that the choice returned:
https://docs.daml.com/json-api/index.html#exercise-response
You will have to model the buyer-seller relationship in your DAML.
Thanks Leonid. I guess my question is about how to create that buyer-seller relationship since they are both onboarded by the operator.
I thought of maintaining a list of all buyers and then adding them as observers on the SellerRole contract when a seller is onboarded (and then add every new buyer when one is onboarded). That sounds pretty cumbersome though so looking for a better answer.
@ManishGrover how about something like this
module Main where
template Exchange
with
operator: Party
buyers: [Party]
sellers: [Party]
where
signatory operator
observer buyers
nonconsuming choice AllSellers: [Party] with
buyer: Party
controller buyer
do
assert (buyer `elem` buyers)
return sellers
setup : Scenario [Party]
setup = scenario do
exchangeOperator <- getParty "ExchangeOperator"
buyer1 <- getParty "Buyer1"
buyer2 <- getParty "Buyer2"
buyer3 <- getParty "Buyer3"
seller1 <- getParty "Seller1"
seller2 <- getParty "Seller2"
seller3 <- getParty "Seller3"
exchange <- submit exchangeOperator do
create Exchange with
operator = exchangeOperator
buyers = [buyer1, buyer2]
sellers = [seller1, seller2, seller3]
-- buyer3 is not registered, so they can't see sellers
submitMustFail buyer3 do
exercise exchange AllSellers with buyer = buyer3
submit buyer1 do
exercise exchange AllSellers with buyer = buyer1
@Leonid_Shlyapnikov’s example shows one way, where you create some sort of registry contract. In his example you wouldn’t even need the nonconsuming choice to get the sellers - the buyers are observers so would simply see the Exchange contract.
If you don’t want to disclose buyers amongst each other, then you don’t get around maintaining a contract per buyer. You could, for example, add the seller to each buyer role contract when the seller is onboarded. You mention this is cumbersome but if you key your buyer role contracts it can be done in the same, single onboarding transaction.