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

streak/v0 package

Overview

Package streak is an on-chain check-in streak tracker: call CheckIn once per "day" to keep a streak alive, miss one and it resets to 1.

There is no wall clock on-chain, so a "day" here is a fixed window of BlocksPerDay blocks: day = ChainHeight() / BlocksPerDay. That makes every streak decision a pure function of block height — deterministic, replayable, and impossible to game by waiting for a favourable timestamp.

State is per-caller and append-only in spirit: an address's best streak is never lowered, so breaking a run costs the current streak but not the record.

This is a stateful app with nothing reusable to extract, so it ships as a lone realm rather than a p/ library + demo pair.

Functions

Best

func Best(addr address) int

Best returns addr's record streak, which is never lowered.

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/daily/streak/v0.Best()"

Result

CheckIn

func CheckIn(cur realm) int

CheckIn records a check-in for the caller and returns the resulting streak.

Checking in twice in the same window is rejected — the streak only moves when the window does. A gap of exactly one window continues the streak; any larger gap restarts it at 1.

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/streak/v0" -func "CheckIn" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/streak/v0" -func "CheckIn" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Current

func Current(addr address) int

Current returns addr's live streak — 0 once a window has been missed, even though the stored value only updates on the next check-in.

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/daily/streak/v0.Current()"

Result

Day

func Day() int64

Day returns the current day index.

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/daily/streak/v0.Day()"

Result

Render

func Render(path string) string

Render renders the streak board for gnoweb.

Example
1Render("")          / Render("/") -> leaderboard by best streak
2Render("/<address>")             -> that address's standing

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/daily/streak/v0.Render()"

Result