Search Apps Documentation Source Content File Folder Download Copy Actions Download

getters.gno

3.02 Kb ยท 121 lines
  1package halt
  2
  3import (
  4	"gno.land/p/onbloc/json"
  5)
  6
  7// IsHalted returns true if any of the specified operation types are halted.
  8// Returns error if any operation type is invalid.
  9func IsHalted(opTypes ...OpType) (bool, error) {
 10	for _, op := range opTypes {
 11		if !op.IsValid() {
 12			return true, makeErrorWithDetails(errInvalidOpType, op.String())
 13		}
 14
 15		halted, err := haltStates.IsOperationHalted(op)
 16		if err != nil {
 17			return true, err
 18		}
 19
 20		if halted {
 21			return true, nil
 22		}
 23	}
 24
 25	return false, nil
 26}
 27
 28// GetHaltConfig returns a copy of the current halt configuration.
 29func GetHaltConfig() HaltConfig {
 30	return haltStates.ToConfig()
 31}
 32
 33// GetHaltConfigJson returns the halt configuration as a JSON string.
 34func GetHaltConfigJson() string {
 35	haltConfig := GetHaltConfig()
 36
 37	statusNodes := make(map[string]*json.Node)
 38
 39	for op, halted := range haltConfig {
 40		statusNodes[op.String()] = json.BoolNode(op.String(), halted)
 41	}
 42
 43	objectNode := json.ObjectNode("status", statusNodes)
 44
 45	return objectNode.String()
 46}
 47
 48// IsHaltedPool returns true if pool operations are halted.
 49func IsHaltedPool() bool {
 50	return isHaltedOperation(OpTypePool)
 51}
 52
 53// IsHaltedPosition returns true if position operations are halted.
 54func IsHaltedPosition() bool {
 55	return isHaltedOperation(OpTypePosition)
 56}
 57
 58// IsHaltedProtocolFee returns true if protocol fee operations are halted.
 59func IsHaltedProtocolFee() bool {
 60	return isHaltedOperation(OpTypeProtocolFee)
 61}
 62
 63// IsHaltedRouter returns true if router operations are halted.
 64func IsHaltedRouter() bool {
 65	return isHaltedOperation(OpTypeRouter)
 66}
 67
 68// IsHaltedStaker returns true if staker operations are halted.
 69func IsHaltedStaker() bool {
 70	return isHaltedOperation(OpTypeStaker)
 71}
 72
 73// IsHaltedLaunchpad returns true if launchpad operations are halted.
 74func IsHaltedLaunchpad() bool {
 75	return isHaltedOperation(OpTypeLaunchpad)
 76}
 77
 78// IsHaltedGovernance returns true if governance operations are halted.
 79func IsHaltedGovernance() bool {
 80	return isHaltedOperation(OpTypeGovernance)
 81}
 82
 83// IsHaltedGovStaker returns true if governance staker operations are halted.
 84func IsHaltedGovStaker() bool {
 85	return isHaltedOperation(OpTypeGovStaker)
 86}
 87
 88// IsHaltedXGns returns true if xGNS operations are halted.
 89func IsHaltedXGns() bool {
 90	return isHaltedOperation(OpTypeXGns)
 91}
 92
 93// IsHaltedCommunityPool returns true if community pool operations are halted.
 94func IsHaltedCommunityPool() bool {
 95	return isHaltedOperation(OpTypeCommunityPool)
 96}
 97
 98// IsHaltedEmission returns true if emission operations are halted.
 99func IsHaltedEmission() bool {
100	return isHaltedOperation(OpTypeEmission)
101}
102
103// IsHaltedWithdraw returns true if withdraw operations are halted.
104func IsHaltedWithdraw() bool {
105	return isHaltedOperation(OpTypeWithdraw)
106}
107
108// isHaltedOperation returns halt status for the specified operation type.
109// Panics if operation type is invalid.
110func isHaltedOperation(op OpType) bool {
111	if !op.IsValid() {
112		panic(makeErrorWithDetails(errInvalidOpType, op.String()))
113	}
114
115	halted, err := haltStates.IsOperationHalted(op)
116	if err != nil {
117		panic(err)
118	}
119
120	return halted
121}