func NewTokenBucket
NewTokenBucket creates a bucket starting full (Tokens == capacity). capacity and refillPerBlock must both be positive.
Package ratelimit provides a token-bucket rate limiter for use inside gno.land realms. It holds no chain state itself...
Package ratelimit provides a token-bucket rate limiter for use inside gno.land realms. It holds no chain state itself -- the importing realm owns a *TokenBucket (typically as a struct field or inside an avl.Tree keyed by caller address) and passes in the current block height on every check, since a pure package can't call chain/runtime itself.
NewTokenBucket creates a bucket starting full (Tokens == capacity). capacity and refillPerBlock must both be positive.
TokenBucket implements the classic token-bucket algorithm. Tokens refill linearly with block height and are capped at Capacity.
Allow refills the bucket up to nowBlock, then attempts to spend cost tokens. Returns true and deducts cost if there were enough tokens, false (no deduction) otherwise.
Peek refills the bucket up to nowBlock (mutating LastRefillBlock and Tokens, same as Allow would) and returns the resulting token count, without spending anything. Useful for a read-only "how many do I have right now" view function.