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

connect4 state

Back to all declarations

bech32Value

[256]uint8

bech32Value holds, for each character of the bech32 alphabet "qpzry9x8gf2tvdw0s3jn54khce6mua7l", its 5-bit value plus one. Zero marks every other byte, capitals included.

Open
OID
016c93…41f1:4
bech32Value details

Inspect array

bech32Gen

[32]uint32

bech32Gen\[t] is the XOR of the BIP-173 generators selected by the five bits of t: one table read per character instead of five tests.

Open
OID
016c93…41f1:6
bech32Gen details

Inspect array

bech32PrefixState

uint32

The checksum state once the address prefix "g" has been absorbed, which BIP-173 expands to the values 3, 0, 7.

Value

35847

canonical

func(a .uverse.address) bool

canonical reports whether a is "g1", then 38 lowercase bech32 characters whose checksum is the original bech32 one: the form a caller's address has.

Open
OID
016c93…41f1:7
canonical details

Inspect func

cols

untyped bigint

Value

(7 <untyped> bigint)

rows

untyped bigint

Value

(6 <untyped> bigint)

board

type

board is indexed \[column]\[row]; row 0 is the bottom. 0 = empty, 1/2 = player.

Value

connect4.board

moveTimeout

time.Duration

Value

<zero>

maxOfferTTL

untyped bigint

// minutes

Value

(60 <untyped> bigint)

feeCap

untyped bigint

Value

(500000 <untyped> bigint)

minStake

untyped bigint

// ugnot

Value

(1000000 <untyped> bigint)

denom

untyped string

Value

"ugnot"

Status

type

Value

connect4.Status

Open

connect4.Status

Value

<zero>

Playing

connect4.Status

Value

<zero>

Won

connect4.Status

Value

<zero>

Draw

connect4.Status

Value

<zero>

Void

connect4.Status

Value

<zero>

Cancelled

connect4.Status

Value

<zero>

Game

type

Value

connect4.Game

Stats

type

Value

connect4.Stats

games

v0.Tree

// key(id) -> \*Game

Open
OID
016c93…41f1:10
games details

Inspect ref

active

v0.Tree

// key(id) -> \*Game, only Open and Playing

Open
OID
016c93…41f1:12
active details

Inspect ref

stats

v0.Tree

// address -> \*Stats

Open
OID
016c93…41f1:14
stats details

Inspect ref

nextID

int

Value

2

fee

int64

// ugnot per decisive game

Value

100000

feesCollected

int64

Value

0

owner

*v0.Ownable

// the deployer; nil (no owner) if deployed some other way

Open
OID
016c93…41f1:90
owner details

Inspect pointer

pendingOwner

.uverse.address

// set by TransferOwnership, made owner by AcceptOwnership

Value

<zero>

used

v0.Tree

// address + ":" + commitment -> true, both kinds

Open
OID
016c93…41f1:21
used details

Inspect ref

testSession

bool

Value

false

Offer

func(opponent .uverse.address, validFor int, commitment string, maxFee int64) int

Offer posts a game open for validFor minutes. The stake is the ugnot sent with the call. A non-empty opponent makes the offer private. commitment is the lowercase hex sha256 of a secret passphrase, revealed after Accept.

Open
OID
016c93…41f1:25
Offer details

Inspect func

validateOffer

func(stake int64, validFor int, opponent .uverse.address, commitment string) []string

validateOffer returns every rule an offer breaks. Offer panics with the first; the "new" page lists them all before anyone signs.

Open
OID
016c93…41f1:26
validateOffer details

Inspect func

Accept

func(id int, seedCommitment string)

Accept joins an open offer by sending exactly its stake. seedCommitment is the lowercase hex sha256 of a secret seed, revealed after the creator's passphrase. The creator then has 90s to Reveal.

Open
OID
016c93…41f1:27
Accept details

Inspect func

Reveal

func(id int, passphrase string)

Reveal discloses the creator's passphrase. It must come within 90s of Accept; the acceptor then has 90s to RevealSeed.

Open
OID
016c93…41f1:28
Reveal details

Inspect func

RevealSeed

func(id int, seed string)

RevealSeed discloses the acceptor's seed, which with the creator's passphrase picks the first mover. It must come within 90s of Reveal.

Open
OID
016c93…41f1:29
RevealSeed details

Inspect func

firstMover

func(passphrase string, seed string, g *connect4.Game) uint8

firstMover draws 1 (creator) or 2 (acceptor) from both secrets.

Open
OID
016c93…41f1:30
firstMover details

Inspect func

Play

func(id int, column int, move int)

Play drops a piece in column (1-7). move is the game's move count the player saw (Moves before this piece): a resent or delayed move that the game has moved past is refused instead of being played on a later turn.

Open
OID
016c93…41f1:31
Play details

Inspect func

ClaimTimeout

func(id int)

ClaimTimeout settles a game whose move clock ran out. Anyone may call it.

Open
OID
016c93…41f1:32
ClaimTimeout details

Inspect func

Resign

func(id int)

Resign concedes a game in progress.

Open
OID
016c93…41f1:33
Resign details

Inspect func

Cancel

func(id int)

Cancel withdraws an open offer and refunds the creator. The creator may cancel at any time; anyone may once the offer has expired.

Open
OID
016c93…41f1:34
Cancel details

Inspect func

SetFee

func(amount int64)

SetFee changes the flat house fee, in ugnot, for new offers. Games already offered keep the fee they were created with.

Open
OID
016c93…41f1:35
SetFee details

Inspect func

WithdrawFees

func(to .uverse.address)

WithdrawFees sends all collected fees to to.

Open
OID
016c93…41f1:36
WithdrawFees details

Inspect func

TransferOwnership

func(newOwner .uverse.address)

TransferOwnership names the next owner, who becomes owner by calling AcceptOwnership. Two steps, so a mistyped or non-canonical address can never strand ownership (and the fees): only an address that signs can accept, and it is recorded as it signs.

Open
OID
016c93…41f1:37
TransferOwnership details

Inspect func

AcceptOwnership

func()

AcceptOwnership completes a TransferOwnership; only the named address may call it.

Open
OID
016c93…41f1:38
AcceptOwnership details

Inspect func

useCommitment

func(addr .uverse.address, commitment string)

useCommitment records a commitment for addr, refusing one it already used: a revealed secret is public, so reusing it hands the other side the draw. Keyed by address, so nobody can block another player's commitment.

Open
OID
016c93…41f1:39
useCommitment details

Inspect func

received

func() int64

received returns the ugnot sent with a direct user call. OriginSend only describes a real payment to this realm when the caller is an EOA using maketx call; see docs/resources/effective-gno.md.

Open
OID
016c93…41f1:40
received details

Inspect func

noCoins

func()

noCoins guards calls that take no payment: coins sent with them would be stuck in the realm.

Open
OID
016c93…41f1:41
noCoins details

Inspect func

noSession

func(action string)

noSession refuses calls signed by an account session key.

Open
OID
016c93…41f1:42
noSession details

Inspect func

sha256Hex

func(s string) string
Open
OID
016c93…41f1:43
sha256Hex details

Inspect func

isHexSHA256

func(s string) bool
Open
OID
016c93…41f1:44
isHexSHA256 details

Inspect func

settleWin

func(g *connect4.Game, winner .uverse.address)
Open
OID
016c93…41f1:45
settleWin details

Inspect func

settleDraw

func(g *connect4.Game)
Open
OID
016c93…41f1:46
settleDraw details

Inspect func

settleVoid

func(g *connect4.Game)
Open
OID
016c93…41f1:47
settleVoid details

Inspect func

leader

type

leader is one leaderboard row. The boards are kept at settlement so Render never walks every player's stats.

Value

connect4.leader

topWins

[]connect4.leader

// highest first, at most topN

Value

<zero>

topGnot

[]connect4.leader

// highest first, at most topN

Value

<zero>

topN

untyped bigint

Value

(10 <untyped> bigint)

bump

func(board []connect4.leader, addr .uverse.address, score int64) []connect4.leader

bump moves addr to its new score in board. Scores only grow, so a player already listed can only move up; ties keep the earlier holder first.

Open
OID
016c93…41f1:50
bump details

Inspect func

finish

func(g *connect4.Game, s connect4.Status)
Open
OID
016c93…41f1:51
finish details

Inspect func

send

func(to .uverse.address, amount int64)
Open
OID
016c93…41f1:52
send details

Inspect func

statsOf

func(addr .uverse.address) *connect4.Stats
Open
OID
016c93…41f1:53
statsOf details

Inspect func

key

func(id int) string

key zero-pads ids so avl iteration order matches creation order.

Open
OID
016c93…41f1:54
key details

Inspect func

mustGet

func(id int) *connect4.Game
Open
OID
016c93…41f1:56
mustGet details

Inspect func

GameJSON

func(id int) string

GameJSON returns {"now":\<unix>,"game":\<game>|null}. It is a read-only accessor for clients querying over vm/qeval; now is the block time.

Open
OID
016c93…41f1:57
GameJSON details

Inspect func

ActiveJSON

func(offset int, limit int) string

ActiveJSON returns {"now":\<unix>,"fee":\<ugnot>,"games":\[...]}: the house fee for new offers, then Open and Playing games in id order, skipping offset and returning at most limit (clamped to 1-100).

Open
OID
016c93…41f1:59
ActiveJSON details

Inspect func

writeNow

func(b *strings.Builder)
Open
OID
016c93…41f1:60
writeNow details

Inspect func

writeGame

func(b *strings.Builder, g *connect4.Game)

writeGame emits one game. Every stored string is validated on write (addresses by IsValid, the commitment as hex), so Quote is defence in depth.

Open
OID
016c93…41f1:61
writeGame details

Inspect func

writeStr

func(b *strings.Builder, k string, v string)

writeStr and writeNum append \`,"k":v\`; the caller writes the first field.

Open
OID
016c93…41f1:62
writeStr details

Inspect func

writeNum

func(b *strings.Builder, k string, v int64)
Open
OID
016c93…41f1:63
writeNum details

Inspect func

LeadersJSON

func() string

LeadersJSON returns {"wins":\[...],"gnot":\[...]}: the top-10 boards (most games won, most ugnot won) kept at settlement, highest first. Each entry is {"addr":\<address>,"score":\<int>}.

Open
OID
016c93…41f1:64
LeadersJSON details

Inspect func

writeLeaders

func(b *strings.Builder, board []connect4.leader)
Open
OID
016c93…41f1:65
writeLeaders details

Inspect func

lobbyRows

untyped bigint

lobbyRows caps the games the lobby lists, so Render stays within query gas however many games are open; clients page through ActiveJSON instead.

Value

(50 <untyped> bigint)

red

untyped string

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

"#e53935"

yellow

untyped string

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

"#fdd835"

hole

untyped string

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

"#ffffff"

boardBlue

untyped string

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

"#1565c0"

lastMoveStroke

untyped string

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

"#212121"

winStroke

untyped string

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

"#00e676"

cellPx

untyped bigint

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

(48 <untyped> bigint)

headerPx

untyped bigint

Board colours. gnoweb only embeds SVG as data-URI images, so each column is its own image, wrapped in its Play link while the game is being played.

Value

(20 <untyped> bigint)

Render

func(path string) string

Render serves "" (lobby and leaderboards), "new" (offer form) and "game/\<id>" (one game with every action its state allows). Everything written comes from realm state or from query values that have been validated and re-formatted; raw path input is never echoed.

Open
OID
016c93…41f1:70
Render details

Inspect func

pageURL

func(page string) string

pageURL links to one of this realm's Render pages. The realm path is read at runtime, like txlink does, so links work wherever the realm is deployed.

Open
OID
016c93…41f1:72
pageURL details

Inspect func

renderNew

func(query string) string

renderNew shows the offer form and, once submitted, a single Offer link with the stake and every argument prefilled (gnoweb cannot edit .send).

Open
OID
016c93…41f1:75
renderNew details

Inspect func

renderGame

func(g *connect4.Game) string
Open
OID
016c93…41f1:76
renderGame details

Inspect func

boardView

func(g *connect4.Game, now time.Time) string

boardView draws the board. While a move can be played it is 7 column images, each wrapped in its Play link (gnoweb lays linked images out side by side). Otherwise it is one image of all 7 columns, since gnoweb stacks bare images vertically. The last move gets a dark ring, a winning line a green one.

Open
OID
016c93…41f1:77
boardView details

Inspect func

drawColumn

func(canvas *v0.Canvas, g *connect4.Game, win *[7][6]bool, c int, x int) string

drawColumn draws column c at horizontal offset x and returns its alt text.

Open
OID
016c93…41f1:78
drawColumn details

Inspect func

onTurn

func(g *connect4.Game) string

onTurn names who the game waits for.

Open
OID
016c93…41f1:79
onTurn details

Inspect func

clockLeft

func(g *connect4.Game, now time.Time) string

clockLeft is the time left on the move clock, or "clock ran out". Play is still accepted in the deadline block itself, so zero left is not expired.

Open
OID
016c93…41f1:80
clockLeft details

Inspect func

acceptURL

func(g *connect4.Game) string
Open
OID
016c93…41f1:81
acceptURL details

Inspect func

openTo

func(g *connect4.Game) string
Open
OID
016c93…41f1:83
openTo details

Inspect func

parseGNOT

func(s string) (int64, bool)

parseGNOT parses a decimal GNOT amount ("10", "2.5") into ugnot.

Open
OID
016c93…41f1:84
parseGNOT details

Inspect func

leaderboard

func(board []connect4.leader, format func(...)) string

leaderboard renders a board kept at settlement (topWins, topGnot).

Open
OID
016c93…41f1:85
leaderboard details

Inspect func

gnot

func(ugnot int64) string

gnot formats ugnot as GNOT with up to 6 decimals.

Open
OID
016c93…41f1:86
gnot details

Inspect func

remaining

func(d time.Duration) string
Open
OID
016c93…41f1:87
remaining details

Inspect func

orNone

func(a .uverse.address) string
Open
OID
016c93…41f1:88
orNone details

Inspect func
bech32Value : [256]uint8 Inspect
bech32Gen : [32]uint32 Inspect
bech32PrefixState : uint32 =35847
canonical : func(a .uverse.address) bool Inspect
cols : untyped bigint =(7 <untyped> bigint)
rows : untyped bigint =(6 <untyped> bigint)
board : type =connect4.board
moveTimeout : time.Duration =<zero>
maxOfferTTL : untyped bigint =(60 <untyped> bigint)
feeCap : untyped bigint =(500000 <untyped> bigint)
minStake : untyped bigint =(1000000 <untyped> bigint)
denom : untyped string ="ugnot"
Status : type =connect4.Status
Open : connect4.Status =<zero>
Playing : connect4.Status =<zero>
Won : connect4.Status =<zero>
Draw : connect4.Status =<zero>
Void : connect4.Status =<zero>
Cancelled : connect4.Status =<zero>
Game : type =connect4.Game
Stats : type =connect4.Stats
games : v0.Tree Inspect
active : v0.Tree Inspect
stats : v0.Tree Inspect
nextID : int =2
fee : int64 =100000
feesCollected : int64 =0
owner : *v0.Ownable Inspect
pendingOwner : .uverse.address =<zero>
used : v0.Tree Inspect
testSession : bool =false
init.31 : func() Inspect
Offer : func(opponent .uverse.address, validFor int, commitment string, maxFee int64) int Inspect
validateOffer : func(stake int64, validFor int, opponent .uverse.address, commitment string) []string Inspect
Accept : func(id int, seedCommitment string) Inspect
Reveal : func(id int, passphrase string) Inspect
RevealSeed : func(id int, seed string) Inspect
firstMover : func(passphrase string, seed string, g *connect4.Game) uint8 Inspect
Play : func(id int, column int, move int) Inspect
ClaimTimeout : func(id int) Inspect
Resign : func(id int) Inspect
Cancel : func(id int) Inspect
SetFee : func(amount int64) Inspect
WithdrawFees : func(to .uverse.address) Inspect
TransferOwnership : func(newOwner .uverse.address) Inspect
AcceptOwnership : func() Inspect
useCommitment : func(addr .uverse.address, commitment string) Inspect
received : func() int64 Inspect
noCoins : func() Inspect
noSession : func(action string) Inspect
sha256Hex : func(s string) string Inspect
isHexSHA256 : func(s string) bool Inspect
settleWin : func(g *connect4.Game, winner .uverse.address) Inspect
settleDraw : func(g *connect4.Game) Inspect
settleVoid : func(g *connect4.Game) Inspect
leader : type =connect4.leader
topWins : []connect4.leader =<zero>
topGnot : []connect4.leader =<zero>
topN : untyped bigint =(10 <untyped> bigint)
bump : func(board []connect4.leader, addr .uverse.address, score int64) []connect4.leader Inspect
finish : func(g *connect4.Game, s connect4.Status) Inspect
send : func(to .uverse.address, amount int64) Inspect
statsOf : func(addr .uverse.address) *connect4.Stats Inspect
key : func(id int) string Inspect
get : func(id int) *connect4.Game Inspect
mustGet : func(id int) *connect4.Game Inspect
GameJSON : func(id int) string Inspect
ActiveJSON : func(offset int, limit int) string Inspect
writeNow : func(b *strings.Builder) Inspect
writeGame : func(b *strings.Builder, g *connect4.Game) Inspect
writeStr : func(b *strings.Builder, k string, v string) Inspect
writeNum : func(b *strings.Builder, k string, v int64) Inspect
LeadersJSON : func() string Inspect
writeLeaders : func(b *strings.Builder, board []connect4.leader) Inspect
lobbyRows : untyped bigint =(50 <untyped> bigint)
red : untyped string ="#e53935"
yellow : untyped string ="#fdd835"
hole : untyped string ="#ffffff"
boardBlue : untyped string ="#1565c0"
lastMoveStroke : untyped string ="#212121"
winStroke : untyped string ="#00e676"
cellPx : untyped bigint =(48 <untyped> bigint)
headerPx : untyped bigint =(20 <untyped> bigint)
pieceColor : [3]string Inspect
pieceName : [3]string Inspect
Render : func(path string) string Inspect
pageURL : func(page string) string Inspect
renderLobby : func() string Inspect
renderNew : func(query string) string Inspect
renderGame : func(g *connect4.Game) string Inspect
boardView : func(g *connect4.Game, now time.Time) string Inspect
drawColumn : func(canvas *v0.Canvas, g *connect4.Game, win *[7][6]bool, c int, x int) string Inspect
onTurn : func(g *connect4.Game) string Inspect
clockLeft : func(g *connect4.Game, now time.Time) string Inspect
acceptURL : func(g *connect4.Game) string Inspect
digits : func(s string) bool Inspect
openTo : func(g *connect4.Game) string Inspect
parseGNOT : func(s string) (int64, bool) Inspect
leaderboard : func(board []connect4.leader, format func(...)) string Inspect
gnot : func(ugnot int64) string Inspect
remaining : func(d time.Duration) string Inspect
orNone : func(a .uverse.address) string Inspect