Skip to content
CCPEDIAby Unity Nodes
App Development

How to get a list of Parties in a trigger

5 posts246 views2 likesLast activity Jun 2022

  1. Ashok_RajOP

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

  2. rikotacards

    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.

  3. cocreature 1

    @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.

  4. Ashok_Raj

    @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

  5. Ashok_Raj 1

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