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.

/p/nym-moultest123/x/daily/ratelimit/v0

Directory · 4 Files
README.md Open

gno.land/p/nym-moultest123/x/daily/ratelimit/v0

Deterministic token-bucket rate limiter — a port of golang.org/x/time/rate with the wall clock replaced by a caller-supplied monotonic tick (on-chain, the block height).

A Limiter owns a set of per-key token buckets sharing one rate/burst config. Each bucket refills at rate tokens per tick up to burst; the caller picks what a key is (typically an address) and passes the current tick on every call. Pure integer/float math over persistent avl state — no chain imports, no ambient state, fully replayable.

1import "gno.land/p/nym-moultest123/x/daily/ratelimit/v0"
2
3l := ratelimit.New(0.5, 5.0)     // 0.5 tokens/tick, capacity 5
4l.Allow("g1caller", height)      // consume one token; false if empty
5l.AllowN("g1caller", height, 3)  // consume 3 atomically; false if <3
6l.Tokens("g1caller", height)     // read-only balance (whole tokens)

Live demo: r/moul/x/daily/ratelimitdemo · render it at /r/nym-moultest123/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/p/nym-moultest123/x/daily/ratelimit/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.