Created
January 9, 2021 17:16
-
-
Save coire1/bfa43cd5f5a504cd11704b3c30c08c9e to your computer and use it in GitHub Desktop.
Untitled Project
This file contains hidden or 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
/* Parties */ | |
const jackpot : Party = Role("jackpot"); | |
const player : Party = Role("player"); | |
const initialJackpot : SomeNumber = 10n; | |
const ticketPrice : SomeNumber = 10n; | |
const totalJackpot : Value = AvailableMoney(ada, jackpot) | |
const choiceName : string = "lucky"; | |
const availableNumbers : [Bound] = [Bound(0n, 90n)]; | |
const playerChoice : Action = Choice(ChoiceId(choiceName, player), availableNumbers); | |
const playerChosen : Value = ChoiceValue(ChoiceId(choiceName, player)); | |
const winNumber : SomeNumber = BigInt(Math.random() * 90); | |
const checkWinner : Contract = If(ValueEQ(playerChosen, winNumber), | |
Pay(jackpot, Party(player), ada, totalJackpot, Close), | |
Close); | |
const checkChoice : Contract = When([Case(playerChoice, checkWinner)], 10n, Close); | |
const buyTicket : Contract = When([Case(Deposit(jackpot, player, ada, ticketPrice), checkChoice)], | |
10n, | |
Close | |
) | |
/* The initial contract starts when the bank deposit the initial jackpot */ | |
const startingContract : Contract = When([Case(Deposit(jackpot, jackpot, ada, initialJackpot), buyTicket)], | |
100n, | |
Close) | |
return startingContract; |
This file contains hidden or 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
When | |
[Case | |
(Deposit | |
(Role "jackpot") | |
(Role "jackpot") | |
(Token "" "") | |
(Constant 10) | |
) | |
(When | |
[Case | |
(Deposit | |
(Role "jackpot") | |
(Role "player") | |
(Token "" "") | |
(Constant 10) | |
) | |
(When | |
[Case | |
(Choice | |
(ChoiceId | |
"lucky" | |
(Role "player") | |
) | |
[Bound 0 90] | |
) | |
(If | |
(ValueEQ | |
(ChoiceValue | |
(ChoiceId | |
"lucky" | |
(Role "player") | |
)) | |
(Constant 90) | |
) | |
(Pay | |
(Role "jackpot") | |
(Party (Role "player")) | |
(Token "" "") | |
(AvailableMoney | |
(Role "jackpot") | |
(Token "" "") | |
) | |
Close | |
) | |
Close | |
)] | |
10 Close | |
)] | |
10 Close | |
)] | |
100 Close |
This file contains hidden or 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