Created
March 6, 2017 01:00
-
-
Save antonyip/c3fad77b94b3b6abbfc7afbcc81bab37 to your computer and use it in GitHub Desktop.
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
^declare currentTime | |
^declare ticketPrice | |
^declare minNumPlayers | |
^declare endTime | |
^declare buffer1 | |
^declare deadAT | |
^declare currentWinner | |
^declare currentTickets | |
^declare previousBalance | |
^declare currentBalance | |
^declare winnerPercent | |
^comment when the program starts for the next time, it will start from here. | |
PCS | |
^comment This is the start of the program. if it is not the first run, skip to start. | |
BNZ $currentTime :Update | |
^comment If this is the first time running, set some default variables. | |
Start: | |
SET @ticketPrice #0000000ba43b7400 | |
SET @minNumPlayers #000000000000000f | |
SET @winnerPercent #0000000000000050 | |
^comment by default, the creator wins. | |
INC @currentTickets | |
FUN B_to_Address_of_Creator | |
FUN @currentWinner get_B1 | |
^comment Normal AT runs here | |
Update: | |
FUN @currentTime get_Block_Timestamp | |
FUN @prevTime get_Last_Block_Timestamp | |
^comment if Lottery is over, just give me the BURST. | |
BNZ $deadAT :ErrorHandle | |
UpdateNewPlayer: | |
^comment check how much the PlayerPaid and convert to tickets | |
FUN @currentBalance get_Current_Balance | |
SET @newTicks $currentBalance | |
SUB @newTicks $previousBalance | |
DIV @newTicks $ticketPrice | |
^comment You trying to be funny huh. why you send less than ticket price? | |
BZR $newTicks :End | |
^comment update previous balance | |
SET @previousBalance $currentBalance | |
^comment run internal lottery based on past tickets | |
SET @totalTicks $currentTickets | |
ADD @totalTicks $newTicks | |
^comment Random Number Generator | |
SET @myRandomNumber #00000000d00ddaad | |
ADD @myRandomNumber $currentTime | |
^comment based on random number, figure out who won. | |
MOD @myRandomNumber $totalTicks | |
BGT $myRandomNumber $currentTickets :ChangeWinner | |
Update11: | |
^comment update the totalnumber of tickets now | |
SET @currentTickets $totalTicks | |
^comment if the end time is set, jump to update2 | |
BZR $endTime :Update2 | |
^comment if time is up, end the lottery | |
BGT $prevTime $endTime :CloseAuction | |
Update2: | |
^comment if there are enough players, set the end time. | |
BGE $currentTickets $minNumPlayers :SetEndTime | |
Update3: | |
^comment finish this run. | |
JMP :End | |
ChangeWinner: | |
FUN A_to_Tx_after_Timestamp $prevTime | |
FUN B_to_Address_of_Tx_in_A | |
FUN @currentWinner get_B1 | |
JMP :Update11 | |
SetEndTime: | |
^comment do not set endtime again if it has been set | |
BNZ $endTime :Update3 | |
^comment set the end time to current time + 3 days. timestamp is in seconds | |
SET @buffer1 #000000000003F480 | |
ADD @buffer1 $prevTime | |
SET @endTime $buffer1 | |
JMP :Update3 | |
^comment we select a winner here and kill the AT | |
CloseAuction: | |
INC @deadAT | |
FUN set_B1 $currentWinner | |
^comment calculate payout - div 100 * pecent | |
SET @buffer1 #0000000000000064 | |
DIV @currentBalance $buffer1 | |
MUL @currentBalance $winnerPercent | |
FUN send_to_Address_in_B $currentBalance | |
^comment die and give me money. | |
ErrorHandle: | |
FUN B_to_Address_of_Creator | |
FUN send_All_to_Address_in_B | |
^comment reset the AT so that it give me all the money that people test with. | |
End: | |
FIN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment