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

getter_utils.gno

1.12 Kb · 37 lines
 1package launchpad
 2
 3import (
 4	"gno.land/r/gnoswap/launchpad"
 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// cloneProjectEntry is the transformation for the project tree. Project is
12// mutable and its setters are declared in /r/gnoswap/launchpad, so an external
13// holder of the stored pointer could write realm state through it.
14//
15// Project.Clone leaves the project's maps nil; see it for which lookups read
16// them instead.
17func cloneProjectEntry(value any) any {
18	project, ok := value.(*launchpad.Project)
19	if !ok {
20		return nil
21	}
22
23	return project.Clone()
24}
25
26// cloneRewardStateEntry is the transformation for a project tier's reward
27// tree. RewardState is mutable and its setters are declared in
28// /r/gnoswap/launchpad, so an external holder of the stored pointer could
29// write realm state through it.
30func cloneRewardStateEntry(value any) any {
31	rewardState, ok := value.(*launchpad.RewardState)
32	if !ok {
33		return nil
34	}
35
36	return rewardState.Clone()
37}