fairroulette

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2020 License: Apache-2.0, BSD-2-Clause Imports: 10 Imported by: 0

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

View Source
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

View Source
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

View Source
const ProgramHash = "FNT6snmmEM28duSg7cQomafbJ5fs596wtuNRn18wfaAz"

ID of the smart contract program

Variables

This section is empty.

Functions

func GetProcessor

func GetProcessor() vmtypes.Processor

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

func DecodeBetInfo(data []byte) (*BetInfo, error)

func (*BetInfo) Read

func (bi *BetInfo) Read(r io.Reader) error

func (*BetInfo) String

func (b *BetInfo) String() string

func (*BetInfo) Write

func (bi *BetInfo) Write(w io.Writer) error

type PlayerStats

type PlayerStats struct {
	Bets uint32
	Wins uint32
}

Smart contract keep historical stats for players. For fun

func DecodePlayerStats

func DecodePlayerStats(data []byte) (*PlayerStats, error)

func (*PlayerStats) Read

func (ps *PlayerStats) Read(r io.Reader) error

func (*PlayerStats) String

func (ps *PlayerStats) String() string

func (*PlayerStats) Write

func (ps *PlayerStats) Write(w io.Writer) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL