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

config.gno

3.51 Kb · 133 lines
  1package halt
  2
  3// HaltConfig stores halt state for each operation type.
  4type HaltConfig map[OpType]bool
  5
  6// IsHalted returns true if the specified operation is halted, false otherwise.
  7// Returns false if operation type is not found in configuration.
  8//
  9// Parameters:
 10//   - op: operation type whose halt flag is queried.
 11//
 12// Returns:
 13//   - halted: configured halt flag; false when op is absent from the configuration.
 14func (c HaltConfig) IsHalted(op OpType) bool {
 15	halted, exists := c[op]
 16	if !exists {
 17		return false
 18	}
 19
 20	return halted
 21}
 22
 23// Clone creates a deep copy of the halt configuration and returns it.
 24//
 25// Returns:
 26//   - clone: independent map containing the same operation halt flags as the receiver.
 27func (c HaltConfig) Clone() HaltConfig {
 28	clone := make(HaltConfig)
 29
 30	for op, option := range c {
 31		clone[op] = option
 32	}
 33
 34	return clone
 35}
 36
 37// get retrieves halt state for the specified operation type.
 38//
 39// Errors:
 40//   - errOpTypeNotFound: the specified operation type does not exist in the config
 41func (c HaltConfig) get(op OpType) (bool, error) {
 42	enabled, exists := c[op]
 43	if !exists {
 44		return false, makeErrorWithDetails(errOpTypeNotFound, op.String())
 45	}
 46
 47	return enabled, nil
 48}
 49
 50// set updates halt state for the specified operation type.
 51// Returns error if operation type is invalid.
 52func (c HaltConfig) set(op OpType, enabled bool) error {
 53	if !op.IsValid() {
 54		return makeErrorWithDetails(errInvalidOpType, op.String())
 55	}
 56
 57	c[op] = enabled
 58
 59	return nil
 60}
 61
 62// newNoneConfig creates configuration with all operations enabled (no halts).
 63func newNoneConfig() HaltConfig {
 64	return HaltConfig{
 65		OpTypePool:          false,
 66		OpTypePosition:      false,
 67		OpTypeProtocolFee:   false,
 68		OpTypeRouter:        false,
 69		OpTypeStaker:        false,
 70		OpTypeLaunchpad:     false,
 71		OpTypeGovernance:    false,
 72		OpTypeGovStaker:     false,
 73		OpTypeXGns:          false,
 74		OpTypeCommunityPool: false,
 75		OpTypeEmission:      false,
 76		OpTypeWithdraw:      false,
 77	}
 78}
 79
 80// newSafeModeConfig creates configuration for safe mode with only withdrawals halted.
 81func newSafeModeConfig() HaltConfig {
 82	return HaltConfig{
 83		OpTypePool:          false,
 84		OpTypePosition:      false,
 85		OpTypeProtocolFee:   false,
 86		OpTypeRouter:        false,
 87		OpTypeStaker:        false,
 88		OpTypeLaunchpad:     false,
 89		OpTypeGovernance:    false,
 90		OpTypeGovStaker:     false,
 91		OpTypeXGns:          false,
 92		OpTypeCommunityPool: false,
 93		OpTypeEmission:      false,
 94		OpTypeWithdraw:      true,
 95	}
 96}
 97
 98// newEmergencyConfig creates configuration for emergency mode with most operations halted.
 99// Only governance and withdraw operations remain enabled for emergency recovery.
100func newEmergencyConfig() HaltConfig {
101	return HaltConfig{
102		OpTypePool:          true,
103		OpTypePosition:      true,
104		OpTypeProtocolFee:   true,
105		OpTypeRouter:        true,
106		OpTypeStaker:        true,
107		OpTypeLaunchpad:     true,
108		OpTypeGovernance:    false,
109		OpTypeGovStaker:     true,
110		OpTypeXGns:          true,
111		OpTypeCommunityPool: true,
112		OpTypeEmission:      true,
113		OpTypeWithdraw:      false,
114	}
115}
116
117// newCompleteConfig creates configuration with all operations halted for complete lockdown.
118func newCompleteConfig() HaltConfig {
119	return HaltConfig{
120		OpTypePool:          true,
121		OpTypePosition:      true,
122		OpTypeProtocolFee:   true,
123		OpTypeRouter:        true,
124		OpTypeStaker:        true,
125		OpTypeLaunchpad:     true,
126		OpTypeGovernance:    true,
127		OpTypeGovStaker:     true,
128		OpTypeXGns:          true,
129		OpTypeCommunityPool: true,
130		OpTypeEmission:      true,
131		OpTypeWithdraw:      true,
132	}
133}