Skip to content
CCPEDIAby Unity Nodes
App Development

Using find_active on templates with Data types

5 posts321 views1 likesLast activity Mar 2022

  1. Luis_AlmeidaOP

    Hello,

    I am trying to use dazl to query the ledger for Order contracts. If no filters are applied, I can retrieve all the contracts using the find_active function from the AIOPartyClient.

    I have tried to look for examples of filters but didn’t encounter any that filtered using data types, only primitive fields.

    How can I use find_active to filter using a field from a data type inside the template?
    For example, for the Order template in Daml MiB:

    template Order
      with
        operator : Party
        provider : Party
        customer : Party
        status : Status
        details : Details
        providerOrderId : Optional Text
        executions : [Execution]
        remainingQuantity : Decimal
        createdAt : Time
    

    Which has the Details data type:

    data Details = Details with
        id : Text
        listingId : Text
        asset : Asset
        side : Side
        orderType : OrderType
        timeInForce : TimeInForce
        marketType : MarketType
        optExchangeFee : Optional (ContractId AssetDeposit)
      deriving (Eq, Show)
    

    How can I use find_active to get all orders by their details.id?

    Thank you in advance.

  2. dtanabe

    You should be able to do client.find_active(template_id, { "details": { "id": some_value } }); for Python dict's, they’re considered matching if a subset of the fields match.

  3. Luis_Almeida

    Hello, I have tried doing so and I always get empty results. I know the orders exist because I can see them on the navigator and if I find without filters. Do you know what could be the problem?
    Thank you.

  4. dtanabe

    hmm perhaps there is a bug then—another way of doing this is client.find_active(template_id, lambda cdata: cdata["details"]["id"] == some_value) but in the meantime, I’ll look the possible (probable) bug.

  5. Luis_Almeida 1

    I found the problem. I thought the variable I was supplying for the filter was a String but it was actually an Int. It worked now.
    Thank you.