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

v0 source realm

Package ratelimitdemo is a small on-chain demo of the token-bucket rate limiter provided by the [p/moul/x/daily/ratel...

Readme View source

gno.land/r/moul/x/daily/ratelimitdemo/v0

Live demo of the p/moul/x/daily/ratelimit token-bucket rate limiter.

Holds one package-level ratelimit.Limiter (0.5 tokens/block, capacity 5) and wires it to the chain — the tick is runtime.ChainHeight(), each caller is keyed by unsafe.PreviousRealm().Address():

  • Allow(cur) bool — consume one token for the caller.
  • SetConfig(cur, rate, burst) — retune the shared bucket.
  • Tokens(addr) int — read-only balance.
  • Render("/") — config + a table of callers; Render("/addr/<address>") focuses one.

All refill/consume math lives in the library; this realm is just the wiring and the gnoweb view. Render it at /r/moul/x/daily/ratelimitdemo/v0.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/r/moul/x/daily/ratelimitdemo/v0 dependency graph

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package ratelimitdemo is a small on-chain demo of the token-bucket rate limiter provided by the p/moul/x/daily/ratelimit(/p/moul/x/daily/ratelimit/v0) library.

It holds a single package-level ratelimit.Limiter and wires it to the chain: the tick is runtime.ChainHeight() and each caller is keyed by its address (unsafe.PreviousRealm().Address()). It contains no limiter logic of its own — refill/consume math all lives in the library.

Functions 4

func Allow

crossing Action
1func Allow(cur realm) bool
source

Allow consumes one token for the calling realm/user at the current block height and reports whether the request is permitted. Returns false (and consumes nothing) when the caller's bucket is empty.

func Render

1func Render(path string) string
source

Render shows the limiter config and a table of known callers with their current tokens and last-seen height. Path "/addr/<address>" focuses one caller.

func SetConfig

crossing Action
1func SetConfig(cur realm, rate, burst float64)
source

SetConfig updates the shared rate (tokens per block) and burst (capacity). rate is clamped to >= 0, burst to >= 1.

func Tokens

Action
1func Tokens(addr address) int
source

Tokens reports how many whole tokens `addr` has available at the current block height, without mutating any state.

Imports 4

Source Files 3