Documentation
¶
Overview ¶
FairRoulette is a PoC smart contract for IOTA Smart Contracts and the Wasp node In this package smart contract is implemented as a hardcoded Go program. The program is wrapped into the VM wrapper interfaces and uses exactly the same sandbox interface as if it were Wasm VM. The smart contract implements simple gambling dapp. Players can place bets by sending requests to the smart contract. Each request is a value transaction. Smart contract is taking some minimum number of iotas as a reward for processing the transaction (configurable, usually several thousands). The rest of the iotas are taken as a bet placed on particular color on the roulette wheel.
Approx 2 minutes after first bet, the smart contract automatically plays roulette wheel using unpredictable entropy provided by the BLS threshold signatures. This way FairRoulette is provably fair because even committee members can't predict the winning color.
Then smart contract automatically distributes total betted amount to those players which placed their bets on the winning color proportionally to the amount. If nobody places on the winning color the total staked amount remains in the smart contracts account
Index ¶
Constants ¶
const ( // request to place the bet RequestPlaceBet = sctransaction.RequestCode(uint16(1)) // request to lock the bets RequestLockBets = sctransaction.RequestCode(uint16(2)) // request to play and distribute RequestPlayAndDistribute = sctransaction.RequestCode(uint16(3)) // request to set the play period. By default it is 2 minutes. // It only will be processed is sent by the owner of the smart contract RequestSetPlayPeriod = sctransaction.RequestCode(uint16(4) | sctransaction.RequestCodeProtected) )
constants for request codes
const ( /// General constants // number of colors NumColors = 5 // automatically lock and play 2 min after first current bet is confirmed DefaultPlaySecondsAfterFirstBet = 120 /// State variables // state array to store all current bets StateVarBets = "bets" // state array to store locked bets StateVarLockedBets = "lockedBets" // state variable to store last winning color. Just for information StateVarLastWinningColor = "lastWinningColor" // 32 bytes of entropy taken from the hash of the transaction which locked current bets StateVarEntropyFromLocking = "entropyFromLocking" // estimated timestamp for next play (nanoseconds) StateVarNextPlayTimestamp = "nextPlayTimestamp" // array color => amount of wins so far StateArrayWinsPerColor = "winsPerColor" // dictionary address => PlayerStats StateVarPlayerStats = "playerStats" /// Request variables (arguments) // request argument to specify color of the bet. It always is taken modulo NumColors, // so there are NumColors possible colors ReqVarColor = "color" // specify play period in seconds ReqVarPlayPeriodSec = "playPeriod" )
string constants for names of state and request argument variables
const ProgramHash = "FNT6snmmEM28duSg7cQomafbJ5fs596wtuNRn18wfaAz"
ID of the smart contract program
Variables ¶
This section is empty.
Functions ¶
func GetProcessor ¶
coonnection of the SC program with the Wasp node
Types ¶
type BetInfo ¶
type BetInfo struct {
Player address.Address
Sum int64
Color byte
// contains filtered or unexported fields
}
BetInfo contains data of the bet
func DecodeBetInfo ¶
type PlayerStats ¶
Smart contract keep historical stats for players. For fun
func DecodePlayerStats ¶
func DecodePlayerStats(data []byte) (*PlayerStats, error)
func (*PlayerStats) String ¶
func (ps *PlayerStats) String() string