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.83 Kb · 33 lines
 1package staker
 2
 3import (
 4	"gno.land/r/gnoswap/gov/staker"
 5)
 6
 7// cloneDelegationEntry is the transformation for the delegation tree.
 8// Delegation is mutable and its setters are declared in /r/gnoswap/gov/staker,
 9// so an external holder of the stored pointer could write realm state through
10// it.
11func cloneDelegationEntry(value any) any {
12	delegation, ok := value.(*staker.Delegation)
13	if !ok {
14		return nil
15	}
16
17	return delegation.Clone()
18}
19
20// cloneDelegationIDsEntry is the transformation for a delegator's delegation
21// tree. The stored value is a slice, so hand out a copy rather than letting a
22// reader write through the shared backing array.
23func cloneDelegationIDsEntry(value any) any {
24	delegationIDs, ok := value.([]int64)
25	if !ok {
26		return nil
27	}
28
29	cloned := make([]int64, len(delegationIDs))
30	copy(cloned, delegationIDs)
31
32	return cloned
33}