Skip to content

Instantly share code, notes, and snippets.

@cocreature
Created June 24, 2021 09:27
Show Gist options
  • Save cocreature/16096ff7858bbfca51b6f635023af17f to your computer and use it in GitHub Desktop.
Save cocreature/16096ff7858bbfca51b6f635023af17f to your computer and use it in GitHub Desktop.
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