Last active
January 9, 2021 14:25
-
-
Save coire1/99453549b2cb01172af92a93f7a41120 to your computer and use it in GitHub Desktop.
SmartLottery - Test
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 = 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 7) | |
) | |
(Pay | |
(Role "jackpot") | |
(Party (Role "player")) | |
(Token "" "") | |
(AvailableMoney | |
(Role "jackpot") | |
(Token "" "") | |
) | |
Close | |
) | |
Close | |
)] | |
120 Close | |
)] | |
110 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