Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

getter_utils.gno

0.69 Kb · 24 lines
 1package pool
 2
 3import (
 4	pl "gno.land/r/gnoswap/pool"
 5)
 6
 7// The functions below are makeEntrySafeFn transformations handed to
 8// rotree.Wrap. They run on every read through a read-only view, so each one
 9// returns a value the caller may hold without reaching realm-owned state.
10
11// clonePoolEntry is the transformation for the pool tree. Pool is mutable and
12// its setters are declared in /r/gnoswap/pool, so an external holder of the
13// stored pointer could write realm state through it.
14//
15// Pool.Clone leaves the pool's collections nil; see it for which lookups read
16// them instead.
17func clonePoolEntry(value any) any {
18	pool, ok := value.(*pl.Pool)
19	if !ok {
20		return nil
21	}
22
23	return pool.Clone()
24}