Skip to content

Instantly share code, notes, and snippets.

@coire1
Last active January 9, 2021 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coire1/99453549b2cb01172af92a93f7a41120 to your computer and use it in GitHub Desktop.
Save coire1/99453549b2cb01172af92a93f7a41120 to your computer and use it in GitHub Desktop.
SmartLottery - Test
/* 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;
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment