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

getters.gno

4.60 Kb · 172 lines
  1package halt
  2
  3import (
  4	"gno.land/p/onbloc/json/v0"
  5)
  6
  7// IsHalted returns true if any of the specified operation types are halted.
  8// Returns error if any operation type is invalid.
  9//
 10// Parameters:
 11//   - opTypes: operation types to inspect; an empty list reports no halted operations
 12//
 13// Returns:
 14//   - halted: true when any requested operation is halted; on invalid input it
 15//     is also true alongside the error
 16//   - error: nil when all requested operation types are valid and inspected;
 17//     an invalid-operation or state error otherwise
 18func IsHalted(opTypes ...OpType) (bool, error) {
 19	for _, op := range opTypes {
 20		if !op.IsValid() {
 21			return true, makeErrorWithDetails(errInvalidOpType, op.String())
 22		}
 23
 24		halted, err := haltStates.IsOperationHalted(op)
 25		if err != nil {
 26			return true, err
 27		}
 28
 29		if halted {
 30			return true, nil
 31		}
 32	}
 33
 34	return false, nil
 35}
 36
 37// GetHaltConfig returns a copy of the current halt configuration.
 38//
 39// Returns:
 40//   - config: copy of the current halt status keyed by operation type
 41func GetHaltConfig() HaltConfig {
 42	return haltStates.ToConfig()
 43}
 44
 45// GetHaltConfigJson returns the halt configuration as a JSON string.
 46//
 47// Returns:
 48//   - json: JSON object containing each operation type's halt status
 49func GetHaltConfigJson() string {
 50	haltConfig := GetHaltConfig()
 51
 52	statusNodes := make(map[string]*json.Node)
 53
 54	for op, halted := range haltConfig {
 55		statusNodes[op.String()] = json.BoolNode(op.String(), halted)
 56	}
 57
 58	objectNode := json.ObjectNode("status", statusNodes)
 59
 60	return objectNode.String()
 61}
 62
 63// IsHaltedPool returns true if pool operations are halted.
 64//
 65// Returns:
 66//   - halted: true when pool operations are halted; false otherwise
 67func IsHaltedPool() bool {
 68	return isHaltedOperation(OpTypePool)
 69}
 70
 71// IsHaltedPosition returns true if position operations are halted.
 72//
 73// Returns:
 74//   - halted: true when position operations are halted; false otherwise
 75func IsHaltedPosition() bool {
 76	return isHaltedOperation(OpTypePosition)
 77}
 78
 79// IsHaltedProtocolFee returns true if protocol fee operations are halted.
 80//
 81// Returns:
 82//   - halted: true when protocol-fee operations are halted; false otherwise
 83func IsHaltedProtocolFee() bool {
 84	return isHaltedOperation(OpTypeProtocolFee)
 85}
 86
 87// IsHaltedRouter returns true if router operations are halted.
 88//
 89// Returns:
 90//   - halted: true when router operations are halted; false otherwise
 91func IsHaltedRouter() bool {
 92	return isHaltedOperation(OpTypeRouter)
 93}
 94
 95// IsHaltedStaker returns true if staker operations are halted.
 96//
 97// Returns:
 98//   - halted: true when staker operations are halted; false otherwise
 99func IsHaltedStaker() bool {
100	return isHaltedOperation(OpTypeStaker)
101}
102
103// IsHaltedLaunchpad returns true if launchpad operations are halted.
104//
105// Returns:
106//   - halted: true when launchpad operations are halted; false otherwise
107func IsHaltedLaunchpad() bool {
108	return isHaltedOperation(OpTypeLaunchpad)
109}
110
111// IsHaltedGovernance returns true if governance operations are halted.
112//
113// Returns:
114//   - halted: true when governance operations are halted; false otherwise
115func IsHaltedGovernance() bool {
116	return isHaltedOperation(OpTypeGovernance)
117}
118
119// IsHaltedGovStaker returns true if governance staker operations are halted.
120//
121// Returns:
122//   - halted: true when governance-staker operations are halted; false otherwise
123func IsHaltedGovStaker() bool {
124	return isHaltedOperation(OpTypeGovStaker)
125}
126
127// IsHaltedXGns returns true if xGNS operations are halted.
128//
129// Returns:
130//   - halted: true when xGNS operations are halted; false otherwise
131func IsHaltedXGns() bool {
132	return isHaltedOperation(OpTypeXGns)
133}
134
135// IsHaltedCommunityPool returns true if community pool operations are halted.
136//
137// Returns:
138//   - halted: true when community-pool operations are halted; false otherwise
139func IsHaltedCommunityPool() bool {
140	return isHaltedOperation(OpTypeCommunityPool)
141}
142
143// IsHaltedEmission returns true if emission operations are halted.
144//
145// Returns:
146//   - halted: true when emission operations are halted; false otherwise
147func IsHaltedEmission() bool {
148	return isHaltedOperation(OpTypeEmission)
149}
150
151// IsHaltedWithdraw returns true if withdraw operations are halted.
152//
153// Returns:
154//   - halted: true when withdrawal operations are halted; false otherwise
155func IsHaltedWithdraw() bool {
156	return isHaltedOperation(OpTypeWithdraw)
157}
158
159// isHaltedOperation returns halt status for the specified operation type.
160// Panics if operation type is invalid.
161func isHaltedOperation(op OpType) bool {
162	if !op.IsValid() {
163		panic(makeErrorWithDetails(errInvalidOpType, op.String()))
164	}
165
166	halted, err := haltStates.IsOperationHalted(op)
167	if err != nil {
168		panic(err)
169	}
170
171	return halted
172}