smart contract list
-
@Lexicon Oh. you're supposed to use the text instead of the hex. thats good. and here i was coding in hex..
-
@msgAnton ;) makes it much easier doesnt it lol
-
^declare currentTime ^declare ticketPrice ^declare minNumPlayers ^declare currentNumPlayers ^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: FUN @currentTime get_Creation_Timestamp SET @ticketPrice #0000050000000000 SET @minNumPlayers #000000000000000f SET @winnerPercent #0000000000000050 FUN @previousBalance get_Current_Balance ^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 ^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 run internal lottery based on past tickets SET @totalTicks $currentTickets ADD @totalTicks $newTicks ^comment Random Number Generator FUN put_Last_Block_Hash_In_A SET @myRandomSeed #000000000c5d6215 ADD @myRandomSeed $currentTime FUN set_B1 $myRandomSeed FUN XOR_A_with_B FUN get_A1 $myRandomNumber ^comment based on random number, figure out who won. MOD @myRandomNumber $totalTicks SET @currentTickets $totalTicks BGT $myRandomNumber $currentTickets :ChangeWinner Update11: ^comment if the end time is set, jump to update2 BZR $endTime :Update2 ^comment if time is up, end the lottery BGT $currentTime $endTime :CloseAuction Update2: ^comment if there are enough players, set the end time. BGE $currentNumPlayers $minNumPlayers :SetEndTime Update3: ^comment finish this run. JMP :End ChangeWinner: FUN A_to_Tx_after_Timestamp FUN @currentWinner get_Ticket_Id_for_Tx_in_A 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. SET @buffer1 #00000000000010e0 FUN @endTime add_Minutes_to_Timestamp $currentTime $buffer1 JMP :Update3 ^comment we select a winner here and kill the AT CloseAuction: INC @deadAT FUN set_B1 $currentWinner ^comment calculate payout SET @buffer1 #000000000000000a 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: FINShould work as a lottery.. Now i just need to find out how to test my code.
-
@msgAnton you could try the ATDebugger
I'm trying hard to wrap my head around all of this but damn its hard!-/
Also tried to run your code through the Debugger but it never came to an end! Not even after clicking through 1200 Blocks!-/
-
@msgAnton said in smart contract list:
^declare currentTime
^declare ticketPrice
^declare minNumPlayers
^declare currentNumPlayers
^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:
FUN @currentTime get_Creation_Timestamp
SET @ticketPrice #0000050000000000
SET @minNumPlayers #000000000000000f
SET @winnerPercent #0000000000000050
FUN @previousBalance get_Current_Balance
^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
^comment if Lottery is over, just give me the BURST.
BNZ $deadAT :ErrorHandleUpdateNewPlayer:
^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 run internal lottery based on past tickets
SET @totalTicks $currentTickets
ADD @totalTicks $newTicks
^comment Random Number Generator
FUN put_Last_Block_Hash_In_A
SET @myRandomSeed #000000000c5d6215
ADD @myRandomSeed $currentTime
FUN set_B1 $myRandomSeed
FUN XOR_A_with_B
FUN get_A1 $myRandomNumber
^comment based on random number, figure out who won.
MOD @myRandomNumber $totalTicks
SET @currentTickets $totalTicks
BGT $myRandomNumber $currentTickets :ChangeWinnerUpdate11:
^comment if the end time is set, jump to update2
BZR $endTime :Update2
^comment if time is up, end the lottery
BGT $currentTime $endTime :CloseAuctionUpdate2:
^comment if there are enough players, set the end time.
BGE $currentNumPlayers $minNumPlayers :SetEndTimeUpdate3:
^comment finish this run.
JMP :EndChangeWinner:
FUN A_to_Tx_after_Timestamp
FUN @currentWinner get_Ticket_Id_for_Tx_in_A
JMP :Update11SetEndTime:
^comment do not set endtime again if it has been set
BNZ $endTime :Update3
^comment set the end time to current time + 3 days.
SET @buffer1 #00000000000010e0
FUN @endTime add_Minutes_to_Timestamp $currentTime $buffer1
JMP :Update3^comment we select a winner here and kill the AT
CloseAuction:
INC @deadAT
FUN set_B1 $currentWinner
^comment calculate payout
SET @buffer1 #000000000000000a
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:
FINill try it now. do a small local test to see if it works.
-
@msgAnton i have a couple of questions about your code since i can't understand the code: xD
1 - What is supposed to be the fee for the creator of the AT?
2 - What is the ticket price in your code? (i think its 5 burst but just to be sure...)
3 - How long is suposed to take a until a draw happen?
4 - How many players are the minimum for the draw to happen?Sorry for all the questions but i want to launch a lottery for a long time now and i simply can't understand the code... ;D
-
If someone gets them running they will get listed here https://wallet.nixxda.ninja:8125/atlotteries.html
Nop, dont get all exited the listed ones are all expired or did not work!-/ at least I think so!
and why do most of the tickets cost 7.0002016 Burst? because those Lotteries started in 2017?? ;-)
this is just an html I found somewhere in the depths of the forums....But it seems to work!
-
@Lexicon Code doesn't work. I tested it on the AT_Debugger. Need alot more stuffs to get it working. I still need to figure out how to get the burst address of the buyer. Thats my main blocking point. seems like AT debugger is working fine. i needa cross check this with the ciyam.cpp thing.
@gpedro I think the standard fee is 1k BURST, by default.. not 100% sure.
Ticket price was supposed to be 500 burst, but the version i sent is totally wrong. 500 burst should be #0000000ba43b7400 :D. Might be easier to advertise the ticket at 550 burst due to code steps..
Draws are 3 days after 16 tickets have been bought. There is no way to auto win tho. someone needs to trigger the AT to complete after 3 days.Every code step takes 1 burst.. on average, it eats up about 20 burst per run.. Might be cheaper to run a php host. lol
-
@msgAnton hmm i guess i will wait a little longer to test it then ;D
Glad you are on this... We really need some ATs deployed! ;D
-
just launched an automated transaction lottery test.
send 550 burst to
BURST-P3MU-THW3-E6M3-HQM7Tto enter the lottery.
edit dont send any more burst to the above address. the at will no longer send out the moneyz it has sent to itlottery should start after 16 players.
lets see how this works XD
-
@Lexicon Send 550 for a ticket or it won't work..
-
@Lexicon as soon as my wallet starts to function and connect to peers agin im in :)
-
@Lexicon ummm...is it 500 or 550? ;-) sent 500...
-
I don't know if Lex made changes to my code or not. If he didn't then you gotta send 550... or it will just eat your money D':
-
its 550 i didnt make the changes to lower it
-
okay you guys can stop, something went wrong.. "frozen":true,"finished":true,
Edit.. maybe don't stop, so i can gather more information on what went wrong.. currently we have 7 tickets.
-
oh well, I sent 500 and 550 ;-) of course its stuck ...
-
Hi Guys,
The AT worked somewhat of the way. there was an error with the timestamp so it hasnt waited 3 days instead just waiting till it had 10 tickets and then picked a "winner" then paid it all out.
it picked the winner as myself and returned the 20% funds to the account so the test was successful and proved that "most" of the logic worked except for an issue with the timestamp.
well done @msgAnton



