Smart Contract
Check it on Mainnet
Explanations
Traits used
These traits enforce those standard are implemented in this smart contract
(use-trait nft-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
(use-trait ft-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)Constants
Used for signaling different errors , an ok messages and the default price used if one can't be found for the lobby
(define-constant ERR-NOT-AUTHORIZED (err u401))
(define-constant ERR-NOT-FOUND (err u404))
(define-constant ERR-NOT-ACTIVE (err u403))
(define-constant ERR-ALREADY-JOINED (err u405))
(define-constant ERR-JOIN-FAILED (err u500))
(define-constant OK-SUCCESS u200)
(define-constant DEFAULT-PRICE u100)Variable Data Stored - Maps and Vars
Store the information for each lobby.
Store the highscore of each user to that lobby.
Keep the count of created lobbies, also used as id for the next lobby.
Keep the admin that makes the smart contract calls to submit highscores, pay users, end lobbies etc.
General Functions
Functions that anyone can call:
Create a lobby.
Join a lobby.
Get a lobby info - read only. Can get the information without paying STX directly calling the endpoint, as it does not write information to the blockchain.
Get the high score of a user address for a specified lobby-id.
Admin Functions
Functions are public but only the admin can pass the asserts to make the calls. This is done for security reasons. Without it, anyone would be able to abuse the information. It also facilitates transparency on-chain by letting everybody see what the admin called.
Simple functions
Disable lobby - ends a specific lobby. After ending it high scores cannot be uploaded to it and payments cannot be done to the users from it.
Set owner - change the admin of the smart contract. The old address will not be able to call the admin functions after the call is confirmed, while the new address will be able afterwards.
Complex functions
Publish - posts the high scores to the blockchain. It gets from the admin a list of maximum 50 high scores for one or more active lobbies and sets them in the scoreboard map.
Finish - when a lobby is done, finish it by submitting the last high scores. Calculate off-chain the rewards for each player who took part in that lobby and call it on-chain to distribute them directly from the pool.
Helper Functions
Functions are private and directly used when they are needed, in other functions.
Increment lobby id.
Add balance - send x amount of STX from the tx-sender and add it to the lobby pool.
Check response is error.is
Safety Functions
Implement the standard trait for transferring assets: STX, FT and NFTs.
Last updated
Was this helpful?