Transaction Details
Open on Dero ExplorerInternal ID:
2756128
Transaction Hash:
9d2c7303f5eb7305933a2a4181ad16641984452e9828f9a4f851566541bb9eb7
Block:
Timestamp:
2022-05-01 18:37:54 UTC (3.4 years ago)
Type:
sc
Ring Size:
2
Payloads:
1
Caller:
…qgj5dq70
(1370619)
SC Data:
[{"name":"SC_ACTION","datatype":"U","value":"1"},{"name":"SC_CODE","datatype":"S","value":"//**** COMMIT LIB, STATE AND TX SAVE ****//\n// All store must go through this function - it saves all transaction and is use to build the database client side\n// You can create pagination with commit_count and fetch 1000 commits at a time - it's scalable\n// actions | s = store | d = delete\nFunction storeCommitString(action String, key String, value String)\n10 DIM commit_count as Uint64\n20 LET commit_count = MAPGET(\"commit_count\")\n30 STORE(\"commit_\" + commit_count, action + \"::\" + key + \"::\" + value)\n40 MAPSTORE(\"commit_count\", commit_count + 1)\n50 RETURN\nEnd Function\n\nFunction storeCommitInt(action String, key String, value Uint64)\n10 DIM commit_count as Uint64\n20 LET commit_count = MAPGET(\"commit_count\")\n30 STORE(\"commit_\" + commit_count, action + \"::\" + key + \"::\" + value)\n40 MAPSTORE(\"commit_count\", commit_count + 1)\n50 RETURN\nEnd Function\n\nFunction initCommit()\n10 STORE(\"commit_count\", 0)\n20 RETURN\nEnd Function\n\nFunction beginCommit()\n10 MAPSTORE(\"commit_count\", LOAD(\"commit_count\"))\n20 RETURN\nEnd Function\n\nFunction endCommit()\n10 STORE(\"commit_count\", MAPGET(\"commit_count\"))\n20 RETURN\nEnd Function\n\n// This functions helps me categorize state between commits\n// If were ever able to fetch by prefix I can just use prefix with \"state_\" and get the current state of the Smart Contract with limit and cursor hash\n// This will avoid building the entire db from commits pagination\nFunction storeStateString(key String, value String)\n10 STORE(\"state_\" + key, value)\n20 storeCommitString(\"S\", \"state_\" + key, value)\n30 RETURN\nEnd Function\n\nFunction storeStateInt(key String, value Uint64)\n10 STORE(\"state_\" + key, value)\n20 storeCommitInt(\"S\", \"state_\" + key, value) // S - store\n30 RETURN\nEnd Function\n\nFunction deleteState(key String)\n10 DELETE(\"state_\" + key)\n20 storeCommitInt(\"D\", \"state_\" + key, 0) // D - delete\n30 RETURN\nEnd Function\n\nFunction loadStateString(key String) String\n10 RETURN LOAD(\"state_\" + key)\nEnd Function\n\nFunction loadStateInt(key String) Uint64\n10 RETURN LOAD(\"state_\" + key)\nEnd Function\n\nFunction stateExists(key String) Uint64\n10 RETURN EXISTS(\"state_\" + key)\nEnd Function\n\nFunction storeTX()\n10 storeStateInt(\"txid_\" + HEX(TXID()), 1) // use this to verify if transaction was stored within the smart contract \n20 RETURN\nEnd Function\n\n//**** LOTTO CODE ****//\nFunction initLottoDraw(lottoKey String, lottoNumber Uint64)\n10 storeStateInt(\"lotto_\" + lottoKey + \"_count\", lottoNumber)\n20 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_count\", 0)\n30 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_max_tickets\", loadStateInt(\"lotto_\" + lottoKey + \"_max_tickets\"))\n40 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_price\", loadStateInt(\"lotto_\" + lottoKey + \"_ticket_price\"))\n50 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_winner_reward\", loadStateInt(\"lotto_\" + lottoKey + \"_winner_reward\"))\n60 RETURN\nEnd Function\n\nFunction drawLotto(lottoKey String, lottoNumber Uint64, ticketCount Uint64)\n10 DIM winner_number as Uint64\n20 LET winner_number = RANDOM(ticketCount) // zero is inclusive and limit is exclusive\n30 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_redeemed\", 0)\n40 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_draw_timestamp\", BLOCK_TIMESTAMP())\n50 storeStateString(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_winner\", loadStateString(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_\" + winner_number + \"_owner\"))\n60 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_winner_number\", winner_number)\n70 initLottoDraw(lottoKey, lottoNumber + 1) // create new draw for next lotto\n80 RETURN\nEnd Function\n\nFunction setLotto(lottoKey String, maxTickets Uint64, ticketPrice Uint64, winnerReward Uint64) // reward normalize to 1\n10 storeStateInt(\"lotto_\" + lottoKey + \"_max_tickets\", maxTickets)\n20 storeStateInt(\"lotto_\" + lottoKey + \"_ticket_price\", ticketPrice)\n30 IF winnerReward \u003e 0 THEN GOTO 50\n40 RETURN 1\n50 IF winnerReward \u003c= 100 THEN GOTO 70\n60 RETURN 1\n70 storeStateInt(\"lotto_\" + lottoKey + \"_winner_reward\", maxTickets * ticketPrice * winnerReward / 100)\n80 IF stateExists(\"lotto_\" + lottoKey + \"_count\") == 1 THEN GOTO 100 // skip initLottoDraw if already exists\n90 initLottoDraw(lottoKey, 0)\n100 RETURN\nEnd Function\n\nFunction SetLotto(lottoKey String, maxTickets Uint64, ticketPrice Uint64, winnerReward Uint64) Uint64\n10 IF LOAD(\"sc_owner\") == SIGNER() THEN GOTO 30\n20 RETURN 1\n30 beginCommit()\n40 setLotto(lottoKey, maxTickets, ticketPrice, winnerReward)\n50 endCommit()\n60 RETURN 0\nEnd Function\n\nFunction Play(lottoKey String, lottoNumber Uint64) Uint64\n10 DIM ticket_count, max_tickets as Uint64\n12 IF stateExists(\"lotto_\" + lottoKey + \"_disabled\") == 0 THEN GOTO 20 // disabled implement in case something happens and I want to pause the lottery, delete the draw and reimburse everybody\n14 RETURN 1\n20 LET ticket_count = loadStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_count\")\n30 LET max_tickets = loadStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_max_tickets\")\n40 IF ticket_count \u003c max_tickets THEN GOTO 60\n50 RETURN 1\n60 IF DEROVALUE() == loadStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_price\") THEN GOTO 80\n70 RETURN 1\n80 beginCommit()\n90 storeStateString(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_\" + ticket_count + \"_owner\", ADDRESS_STRING(SIGNER())) // new ticket\n100 storeStateString(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_\" + ticket_count + \"_tx_id\", HEX(TXID())) // using hex over txid seams overkill but I need it to decode properly client side\n105 storeTX()\n110 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_\" + ticket_count + \"_timestamp\", BLOCK_TIMESTAMP())\n120 LET ticket_count = ticket_count + 1\n130 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_ticket_count\", ticket_count)\n140 IF ticket_count \u003c max_tickets THEN GOTO 160 // recheck count and if all tickets has been bought draw the lotto - last ticket bought will cost more fees :S\n150 drawLotto(lottoKey, lottoNumber, ticket_count)\n160 endCommit()\n170 RETURN 0\nEnd Function\n\nFunction ClaimReward(lottoKey String, lottoNumber Uint64) Uint64\n10 IF loadStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_redeemed\") == 0 THEN GOTO 30\n20 RETURN 1 // skip - lotto already redeemed\n30 SEND_DERO_TO_ADDRESS(ADDRESS_RAW(loadStateString(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_winner\")), loadStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_winner_reward\"))\n40 beginCommit()\n50 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_redeemed\", 1)\n60 storeStateString(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_claim_tx_id\", HEX(TXID()))\n70 storeTX()\n80 storeStateInt(\"lotto_\" + lottoKey + \"_draw_\" + lottoNumber + \"_claim_timestamp\", BLOCK_TIMESTAMP())\n90 endCommit()\n100 RETURN 0\nEnd Function\n\nFunction DisableLotto(lottoKey String, disable Uint64) Uint64\n10 IF LOAD(\"sc_owner\") == SIGNER() THEN GOTO 30\n20 RETURN 1\n30 beginCommit()\n40 IF disable == 1 THEN GOTO 80\n50 deleteState(\"lotto_\" + lottoKey + \"_disabled\")\n60 endCommit()\n70 RETURN 0\n80 storeStateInt(\"lotto_\" + lottoKey + \"_disabled\", disable)\n90 endCommit()\n100 RETURN 0\nEnd Function\n\n// Withdraw in case I want to reimburse users - I could implement something within the smart contract but it's not practical if there is a lot of tickets to reimburse\nFunction Withdraw(amount Uint64) Uint64\n10 DIM owner as String\n20 LET owner = LOAD(\"sc_owner\")\n30 IF owner == SIGNER() THEN GOTO 50\n40 RETURN 1\n50 SEND_DERO_TO_ADDRESS(owner, amount)\n60 RETURN 0\nEnd Function\n\nFunction Initialize() Uint64\n10 STORE(\"sc_owner\", SIGNER())\n20 initCommit()\n30 beginCommit()\n40 setLotto(\"kono\", "2", 100000, 95)\n41 setLotto(\"unocon\", "4", 50000, 90)\n42 setLotto(\"haylax\", "2", 500000, 95)\n43 setLotto(\"quadla\", "4", 200000, 90)\n44 setLotto(\"dimi\", "2", 2000000, 95)\n45 setLotto(\"vivan\", "4", 1000000, 90)\n50 endCommit()\n60 RETURN 0\nEnd Function\n\nFunction ClaimOwnership() Uint64\n10 IF LOAD(\"sc_owner_temp\") == SIGNER() THEN GOTO 30\n20 RETURN 1\n30 STORE(\"sc_owner\", SIGNER())\n40 RETURN 0\nEnd Function\n\nFunction TransferOwnership(newOwner String) Uint64\n10 IF LOAD(\"sc_owner\") == SIGNER() THEN GOTO 30\n20 RETURN 1\n30 STORE(\"sc_owner_temp\", ADDRESS_RAW(newOwner))\n40 RETURN 0\nEnd Function\n\n// For now I will keep the UpdateCode func just in case\n// But if there is no issue I can remove it and make the smart contract non fungible and keep the SetNewParams to change variable\nFunction UpdateCode(code String) Uint64\n10 IF LOAD(\"sc_owner\") == SIGNER() THEN GOTO 30\n20 RETURN 1\n30 UPDATE_SC_CODE(code)\n40 RETURN 0\nEnd Function"}]
Payload
Token (SCID):
DERO
Deposited:
none
Fees:
0.13171 DERO