How to get a list of Parties in a trigger

In triggers, what is the best way to get all active parties on the ledger?

Someone correct me if I’m mistaken, but I don’t think you can get all active parties via triggers.
You can however

  1. create a User template, and provide a publicParty to the observer field.
  2. Get all active User contracts

The code in create-daml-app does this.

@rikotacards is right, adding on top of that the party management endpoint requires admin claims. That means writing apps that should run for individual users is usually a bad idea since it means you need to give everyone admin claims.

1 Like

@cocreature I have created a alias template

Template Alias
   with 
        alice : Party
        bob : Party
   signatory alice
   observer bob

In the script, I have created the Alias contract and its visible in the results. Now i want to run a trigger and the trigger should be able to access the party alice. The trigger is going to be run by bob.

so here is the portion of my trigger, this is a support function i am using, I am looking at an auction happening, as soon as auction happens, i am querying all auction then calling the support function against each auction. Within the support function I want to access the party alice, I am facing issue accessing this. The


trigrSupFunc  : Auction.Auction ->  TriggerA () ()

trigSupFunc auc = do

  
    queryResults <- query @Alias.Market        -- Alias is imported properly  
    let markets = map snd queryResults
    debug $ "SD2 :"<> show (length queryResults)

markets contain all the market contracts, in this case there is only one so how do i access that contract out of the list and eventually access alice: party

I tried

markets.alice

and

let market = markets._1
market.alice

I also tried head, last to extract the contract out of the list

Also markets !! 0 , throws variable not in scope error

missed to import DA.List, importing it solved the issue.

1 Like