Skip to content

Instantly share code, notes, and snippets.

@marco-martins
Last active June 14, 2022 15:58
Show Gist options
  • Save marco-martins/98fd0e55197566b591d96e57f78149cb to your computer and use it in GitHub Desktop.
Save marco-martins/98fd0e55197566b591d96e57f78149cb to your computer and use it in GitHub Desktop.
choice-if-let.js
{"valueParameterInfo":[],"timeParameterDescriptions":[],"roleDescriptions":[],"contractType":"Other","contractShortDescription":"Unknown","contractName":"choice-if-let.hs","contractLongDescription":"We couldn't find information about this contract","choiceInfo":[]}
function mainFunction(giver: Party, chooser: Party, receiver1: Party, receiver2: Party, choiceDeadline: Timeout, depositDeadline: Timeout): Contract {
let amount: Value = Constant(100000000)
let choice: ChoiceId = ChoiceId("Choice", chooser)
return When([
Case(
Deposit(giver, giver, ada, amount),
When([
Case(
// Value to choose between 1 and 2
Choice(choice, [Bound(1, 2)]),
// Evaluation IF, THEN, ELSE
If (ValueEQ(ChoiceValue(choice), Constant(1)),
Pay(giver, Party(receiver1), ada, amount, Close),
Pay(giver, Party(receiver2), ada, amount, Close)
)
),
], choiceDeadline, Close)
)
], depositDeadline, Close)
}
return mainFunction(
Role("Giver"),
Role("Chooser"),
Role("Receiver1"),
Role("Receiver2"),
TimeParam("ChoiceDeadline"),
TimeParam("DepositDeadline")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment