0

I want to have a Map of (Party, CustomObj) as an attribute/argument in my Contract Template. Also I want to specify the list of keys as observers in the Contract Template. How can I achieve this?

Thanks.

Anurag
  • 45
  • 7

1 Answers1

2

observer accepts arbitrary expressions with the template arguments in scope. So you can write an expression that extracts the keys from your map. To do so, first convert to a list of (key, value) pairs and then use map fst to throw away the values. Here’s a full example:

module Main where

import DA.Next.Map (Map)
import qualified DA.Next.Map as Map

data CustomObj = CustomObj
  deriving (Eq, Show)

template T
  with
    sig : Party
    m : Map Party CustomObj
  where
    signatory sig
    observer map fst (Map.toList m)
cocreature
  • 801
  • 5
  • 5