Skip to content

Smartlinkhub/Lottery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Discord Telegram LinkedIn Twitter Reddit portfolio_view

Smartlink

Smartlink addresses one of the biggest challenges in the global marketplace: ‘Need to Trust,’ by introducing decentralized escrow services and payments processing based on Tezos' institutional-grade smart contracts that suppress the need for buyers and sellers to trust each other.

Smartlink aims to provide a user-centered escrow solution to secure online and face-to-face transactions while broadening payments acceptance options through integrated cryptocurrencies.

Smartlink proposes a new method to initiate commercial transactions by offering Trust-As-A-Service to incentivize commitment and eliminate the trust deficit in the global marketplace.

🎱 Lottery

This lottery contract is quite simple and can be modified easily to change the lottery parameters (ticket price, winning prize and number of tickets / round).

Variables

Name Type Description
admin TAddress Address of the admin
FA12TokenContract TAddress Address of the token contract
hashed_salts TBig_map(TNat, TBytes) Mapping of the round number to the hashed salt used to compute the random winning number
id TNat Number of the current ticket to be sold
limit TNat Maximum number of tickets sold before picking a winner
previous_winners TBig_map(TNat, TRecord(winner : TAddress, ticket : TNat)) Mapping of the round to the winner and his ticket number
paused TBool Bool to pause the contract
price TNat Price of a ticket
reserve TAddress Address of the token reserve to pay the lottery winners
round_num TNat Current round number
tickets TBig_map(TNat, TAddress) Mapping of the ticket number to the address of its owner
user_map TMap(TAddress, TList(sp.TNat)) Mapping of every user for this round and all his tickets
winning_data TBig_map(TNat,sp.TRecord(time = sp.TBytes, volume = sp.TBytes, salt = sp.TBytes)) Mapping of the round number and the data used to compute the random winning number
winning_price TNat Amount of SMAK to be won

buyTicket:

@sp.entry_point
def buyTicket(self, params):
    sp.set_type(params, sp.TNat)

Function that will sell the number of tickets entered as a parameter to a user.

selectWinner:

@sp.entry_point
def selectWinner(self, params):
    sp.verify(~self.data.paused, Error.Paused)
    sp.verify(sp.sender == self.data.admin, Error.AccessDenied)
    sp.verify(self.data.id == self.data.limit, Error.TicketsRemaining)
    sp.set_type(params, sp.TNat)

Function that will select a winner with the number given by the admin. Only the admin can call this function and this function can only be called when all tickets are sold. More information is provided on the random number selection.

resetLottery:

def resetLottery(self):
    self.data.id = sp.nat(0)
    sp.for i in sp.range(0, self.data.limit):
        del self.data.tickets[i]

Function that will delete all the tickets.

save_data:

@sp.entry_point
def save_data(self, params):
    sp.verify(~self.data.paused, Error.Paused)
    sp.verify(sp.sender == self.data.admin, Error.AccessDenied)
    sp.set_type(params, win_data)

Function that will save the data used for computing the random number. Only the admin can call this function and this function.

save_hashed_salt:

@sp.entry_point
def save_hashed_salt(self, params):
    sp.verify(~self.data.paused, Error.Paused)
    sp.verify(sp.sender == self.data.admin, Error.AccessDenied)
    sp.set_type(params, sp.TBytes)
    self.data.hashed_salts[self.data.round_num] = params

Function that will save the hashed salt that will be used to compute the random number. Only the admin can call this function.

pause:

@sp.entry_point
def pause(self, params):
    sp.set_type(params, sp.TUnit)
    sp.verify(sp.sender == self.data.admin, Error.AccessDenied)
    self.data.paused = sp.bool(True) 

Function that will pause the contract. Only the admin can call this function.

About

🎱 A decentralized Lottery Dapp on Tezos.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages