Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module FoldOverParties where
import DA.Action
template ContractB
with
p : Party
data1 : Text
data2 : Text
where
signatory p
template ContractA
with
p : Party
keyData : Text
data1 : Text
data2 : Text
where
signatory p
key (p, keyData) : (Party, Text)
maintainer key._1
template T
with
p : Party
keyData : Text
where
signatory p
choice CollabResult : ContractId ContractB
with
parties : [Party]
controller p
do let data1 = ""; data2 = ""
let process (data1, data2) party = do
(cid, someData) <- fetchByKey @ContractA (p, keyData)
pure if someData.p == party
then (someData.data1, data2)
else (data1, someData.data2)
(data1, data2) <- foldlA process ("", "") parties
create ContractB with data1, data2, p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment