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

persistedcap package

Overview

Package persistedcap stores a closure (constructed by a /p/ factory) at init, persisting the closure's captured HIV as part of this realm's state. Foreign-realm callers can grab the closure via GetCounter() and invoke it; the closure body's write to its captured HIV is REJECTED by the readonly check because the HIV is real (NewTime>0) and belongs to a different realm than the caller's m.Realm. The unreal-HIV exception only applies while the HIV is transient — persistence elevates it to a normal realm-owned slot.

Function

GetCounter

func GetCounter() func() int

GetCounter returns the persisted closure. The caller invokes it directly — because the closure's FuncLit lives in /p/ p_closurecap, PushFrameCall's borrow rule does NOT switch m.Realm to persistedcap at invocation. The closure body's write to the captured HIV (PkgID = persistedcap, persisted) therefore runs under the caller's m.Realm, which is the persisted-closure-capture cross-realm case.

SECURITY: deliberate VM-parity-test infrastructure — do NOT copy this pattern in production code. See gno.land/r/tests/vm/crossrealm Closure for the broader rationale.

Command

gnokey query vm/qeval -remote "https://api.gno.berty.io:443" -data "gno.land/r/tests/vm/persistedcap.GetCounter()"

Result