Last active
June 14, 2022 15:58
-
-
Save marco-martins/98fd0e55197566b591d96e57f78149cb to your computer and use it in GitHub Desktop.
choice-if-let.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"valueParameterInfo":[],"timeParameterDescriptions":[],"roleDescriptions":[],"contractType":"Other","contractShortDescription":"Unknown","contractName":"choice-if-let.hs","contractLongDescription":"We couldn't find information about this contract","choiceInfo":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment