Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

shots source realm

Package shots is a pay-to-play penalty shootout against the chain.

Overview

Package shots is a pay-to-play penalty shootout against the chain.

A creator opens a game by choosing its keeper and ball constants and seeding the pot. A challenger joins an open game by paying its entry fee into the pot, then plays a shootout: in every round they take a kick (TakeShot) and then keep against the chain's kick (SubmitKeeperPlan). Five kicks each, finishing early when one side cannot be caught, then sudden death. Win, and the whole pot is paid out; lose, and the entry fee stays in the pot for the next challenger.

Every kick is played out in the transaction that makes it: the player's choices are completed by 32 bytes derived from the block's timestamp (the chain's move and the mishit), and the outcome is penalty.SimulateShot of the ten inputs, recorded so anyone can re-run it. See impl/v1 for what that entropy does and does not guarantee.

This realm's path and entry points are permanent. The rules engine is an implementation realm behind an upgradeable proxy (gno.land/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/upgradeable/v0); the games and their pots live here and survive every upgrade.

Constants 2

const Admin

1const Admin = address("g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm")
source

Admin may accept, roll back or freeze an implementation. The value is the standard test1 account so the tests run unedited; set your own address before deploying (TransferAuthority moves it afterwards).

const Denom

1const Denom = "ugnot"
source

Denom is the coin pots are held in.

Functions 31

func Accept

crossing Action
1func Accept(cur realm, pkgPath string)
source

Accept makes the candidate at pkgPath live. Authority only.

func AddExtension

crossing Action
1func AddExtension(cur realm, pkgPath string)
source

AddExtension lets another realm act as this one. Authority only.

func CancelGame

crossing Action
1func CancelGame(cur realm, gameID uint64)
source

CancelGame refunds the pot to the creator of a game nobody has played yet.

func CreateGame

crossing Action
1func CreateGame(cur realm, entryFee, timeoutBlocks int64, config string) uint64
source

CreateGame opens a game. Send the initial pot with the call (ugnot). config overrides the default constants as "key=value,..." ("" for the defaults; see penalty.ParseConfig). timeoutBlocks 0 picks the default. Returns the game id.

func Forfeit

crossing Action
1func Forfeit(cur realm, gameID uint64)
source

Forfeit ends the current shootout as a loss: the player may resign at any time, anyone else once the player has been idle for the game's timeout.

func Forget

crossing Action
1func Forget(cur realm)
source

Forget drops the rollback history. Authority only.

func Freeze

crossing Action
1func Freeze(cur realm)
source

Freeze ends upgradeability permanently. Authority only.

func GameJSON

Action
1func GameJSON(gameID uint64) string
source

GameJSON returns game id as JSON ("" if it does not exist).

func JoinGame

crossing Action
1func JoinGame(cur realm, gameID uint64)
source

JoinGame starts a shootout in an open game. Send exactly its entry fee.

func ListGames

Action
1func ListGames(status string, offset, limit int) string
source

ListGames returns up to limit games as a JSON array, newest first, optionally filtered by status ("open", "playing", "won", "cancelled"; "" for all).

func Register

crossing Action
1func Register(cur realm, impl Impl)
source

Register records the calling realm as a candidate implementation; an implementation calls it from its own init. Nothing serves until Accept.

func Render

1func Render(path string) string
source

Render shows the games list, one game ("game/<id>") or one shootout ("game/<id>/<session>").

func Rollback

crossing Action
1func Rollback(cur realm)
source

Rollback restores the previous implementation. Authority only.

func SessionJSON

Action
1func SessionJSON(gameID uint64, no int) string
source

SessionJSON returns session no of a game, kicks included, as JSON.

func SimulateShot

Action
1func SimulateShot(aimX, aimY, contactX, contactY, power int64, mishitHex string,
2	direction, speed, jump, reaction uint16, config string) string
source

SimulateShot runs the live outcome function on ten inputs, without touching any state: the taker's aim, contact, power and 48-hex-char mishit seed, and the keeper's four uint16, under config ("" for the defaults). Returns JSON.

func SubmitKeeperPlan

crossing Action
1func SubmitKeeperPlan(cur realm, gameID uint64, direction, speed, jump, reaction uint16) string
source

SubmitKeeperPlan plays the player's keeper plan against the chain's kick for the current round: four uint16 (see penalty.DecodePlan). Returns the kick as JSON.

func TakeShot

crossing Action
1func TakeShot(cur realm, gameID uint64, aimX, aimY, contactX, contactY, power int64) string
source

TakeShot plays the player's kick for the current round against the chain's keeper: aim point on the goal plane (mm), contact offset on the ball (milli-radii) and power (per-mille). Returns the kick as JSON.

func TopUp

crossing Action
1func TopUp(cur realm, gameID uint64)
source

TopUp adds the coins sent to a game's pot.

func TransferAuthority

crossing Action
1func TransferAuthority(cur realm, newOwner address)
source

TransferAuthority hands the power to upgrade to another address.

func VerifySession

Action
1func VerifySession(gameID uint64, no int) bool
source

VerifySession re-runs every recorded kick of a shootout through the live outcome function and reports whether all of them reproduce, so anyone can check a result from the ten recorded inputs alone.

func Withdraw

crossing Action
1func Withdraw(cur realm, pkgPath string)
source

Withdraw drops a candidate. Authority only, or the candidate itself.

func Store

Action
1func Store(_ int, rlm realm) *StateRef
source

Store hands a StateRef to the live implementation, or to a registered extension. Any other realm presents its own cur and is refused.

Types 2

type Impl

interface
 1type Impl interface {
 2	CreateGame(_ int, rlm realm, creator address, deposit, entryFee, timeoutBlocks int64, config string) uint64
 3	JoinGame(_ int, rlm realm, player address, gameID uint64, paid int64)
 4	TopUp(_ int, rlm realm, from address, gameID uint64, paid int64)
 5	TakeShot(_ int, rlm realm, player address, gameID uint64, shot penalty.ShotInput) shootout.Kick
 6	SubmitKeeperPlan(_ int, rlm realm, player address, gameID uint64, plan penalty.KeeperPlan) shootout.Kick
 7	Forfeit(_ int, rlm realm, caller address, gameID uint64)
 8	CancelGame(_ int, rlm realm, caller address, gameID uint64)
 9
10	// SimulateShot is the pure outcome function: six taker inputs (in shot,
11	// mishit seed included) and four keeper inputs, under cfg.
12	SimulateShot(shot penalty.ShotParams, plan penalty.KeeperPlan, cfg penalty.Config) penalty.Result
13
14	// Describe names the implementation for Render.
15	Describe() string
16}
source

Impl is the rules engine. Declared here so every version agrees on one type identity. The methods are non-crossing: this realm threads its own cur in, so an implementation reaching Store is seen as this realm.

The caller's address and the coins received are established by the entry points below and passed in; an implementation cannot be invoked with forged ones from elsewhere, because without this realm's live cur it cannot reach the state at all.

type StateRef

struct
1type StateRef struct {
2	rlm realm
3}
source

StateRef is a permission to read and write the game state, handed to code running on this realm's cur. It carries the caller's realm value and re-checks it on every operation, so it cannot be stashed (the VM refuses to persist a realm value) or replayed after its frame returns.

Methods on StateRef

func Game

method on StateRef
1func (r *StateRef) Game(id uint64) (shootout.Game, bool)
source

Game returns a copy of game id.

func NewGameID

method on StateRef
1func (r *StateRef) NewGameID() uint64
source

NewGameID allocates the next game id.

func Pay

method on StateRef
1func (r *StateRef) Pay(to address, amount int64)
source

Pay sends amount ugnot from this realm's balance to to.

func PutGame

method on StateRef
1func (r *StateRef) PutGame(g shootout.Game)
source

PutGame stores g (by value) under g.ID.

func PutSession

method on StateRef
1func (r *StateRef) PutSession(s shootout.Session)
source

PutSession stores s (by value, kicks copied).

func Session

method on StateRef
1func (r *StateRef) Session(id uint64, no int) (shootout.Session, bool)
source

Session returns a copy of session no of game id, kicks included.

Dependencies

Source Files 4