Transaction
FD8156832CB153…5EF7D50AD8D8
Block 1,651,930 · index 0 · indexed
Summary
- Hash
- FD8156832CB153AB962741E41E5304822276311960EE5A1F7C585EF7D50AD8D8
- Block
- 1,651,930
- Size
- 6291 bytes
- Gas used
- 13,625,740 / 16,350,852
- Fee
- 16351 ugnot
- Status
- success
Messages
Arguments · 13
- #1halt
- #2consts.gno
- #3package halt // Operations that can be halted. const ( OperationExecute = "execute" OperationWithdraw = "withdraw" ) // TargetAll addresses every target at once. const TargetAll = "all" // Targets registered at deployment; more are added with AddTarget. const ( TargetDCA = "dca" TargetLimit = "limit" ) // maxTargetLength bounds a target name. const maxTargetLength = 32 var operations = []string{OperationExecute, OperationWithdraw}
- #4doc.gno
- #5// Package halt holds the halt switches shared by the GnoSwap order realms // (gno.land/r/gnoswap/order/...). // // Each target (an order type such as "dca" or "limit") has a switch per // operation. Admin or governance turns a switch on for one target, or for // every target with TargetAll, and can add targets for new order realms. // Order realms check IsHalted with their own target, which reports the // operation halted when either switch is on, and decide which entry points // each operation guards. // // Operations: // - OperationExecute: creating or executing orders // - OperationWithdraw: executing orders, paying out or refunding funds // // The switches are independent of the GnoSwap protocol halt levels. package halt
- #6errors.gno
- #7package halt import ( ufmt "gno.land/p/nt/ufmt/v0" ) const ( errInvalidOperation = "[GNOSWAP-ORDER-HALT-001] invalid operation" errInvalidTarget = "[GNOSWAP-ORDER-HALT-002] invalid target" errTargetExists = "[GNOSWAP-ORDER-HALT-003] target already exists" ) func makeErrorWithDetails(message string, details string) error { return ufmt.Errorf("%s || %s", message, details) }
- #8gnomod.toml
- #9module = "gno.land/r/gnoswap/order/halt" gno = "0.9"
- #10halt.gno
- #11package halt import ( "chain" "gno.land/p/gnoswap/utils/v1" "gno.land/p/onbloc/json/v0" "gno.land/r/gnoswap/access/v1" ) var ( // targets lists the registered targets, in registration order. targets = []string{TargetDCA, TargetLimit} // halted holds the switches that are on, keyed by "<target>:<operation>". halted = map[string]bool{} ) // AddTarget registers a target, e.g. for a new order realm. // Admin or governance only. // // A target is 1 to 32 characters of lowercase letters, digits, '_', or '-', // and cannot be TargetAll. func AddTarget(cur realm, target string) { caller := cur.Previous() access.AssertIsAdminOrGovernance(caller.Address()) if err := validateTargetName(target); err != nil { panic(err.Error()) } if isTarget(target) { panic(makeErrorWithDetails(errTargetExists, "target("+target+")").Error()) } targets = append(targets, target) chain.Emit( "OrderHaltTargetAdded", "prevAddr", caller.Address().String(), "prevRealm", caller.PkgPath(), "target", target, ) } // SetHalted halts or resumes operation for target. Admin or governance only. // // Parameters: // - target: a registered target, or TargetAll for every target. // - operation: OperationExecute or OperationWithdraw. func SetHalted(cur realm, target string, operation string, isHalted bool) { caller := cur.Previous() access.AssertIsAdminOrGovernance(caller.Address()) if err := validate(target, operation); err != nil { panic(err.Error()) } key := switchKey(target, operation) prevValue := halted[key] if isHalted { halted[key] = true } else { delete(halted, key) } chain.Emit( "OrderHaltUpdated", "prevAddr", caller.Address().String(), "prevRealm", caller.PkgPath(), "target", target, "operation", operation, "prevValue", utils.FormatBool(prevValue), "newValue", utils.FormatBool(isHalted), ) } // IsHalted reports whether operation is halted for target, // by its own switch or by the TargetAll switch. // It panics on an unknown target or operation. func IsHalted(target string, operation string) bool { if err := validate(target, operation); err != nil { panic(err.Error()) } return halted[switchKey(TargetAll, operation)] || halted[switchKey(target, operation)] } // GetTargets returns the registered targets, in registration order. func GetTargets() []string { out := make([]string, len(targets)) copy(out, targets) return out } // GetOperations returns the operations that can be halted. func GetOperations() []string { out := make([]string, len(operations)) copy(out, operations) return out } // GetHaltedJSON returns, as JSON, whether each operation is halted for // target, including the TargetAll switches. func GetHaltedJSON(target string) string { if err := validateTarget(target); err != nil { panic(err.Error()) } nodes := make(map[string]*json.Node, len(operations)) for _, operation := range operations { nodes[operation] = json.BoolNode("", IsHalted(target, operation)) } encoded, err := json.Marshal(json.ObjectNode("", nodes)) if err != nil { panic(err.Error()) } return string(encoded) } func validate(target string, operation string) error { if err := validateTarget(target); err != nil { return err } if !contains(operations, operation) { return makeErrorWithDetails(errInvalidOperation, "operation("+operation+")") } return nil } func validateTarget(target string) error { if target != TargetAll && !isTarget(target) { return makeErrorWithDetails(errInvalidTarget, "target("+target+") is not registered") } return nil } func validateTargetName(target string) error { if target == "" || len(target) > maxTargetLength || target == TargetAll { return makeErrorWithDetails(errInvalidTarget, "target("+target+")") } for _, c := range target { if !(c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '_' || c == '-') { return makeErrorWithDetails(errInvalidTarget, "target("+target+") has an invalid character") } } return nil } func isTarget(target string) bool { return contains(targets, target) } func switchKey(target string, operation string) string { return target + ":" + operation } func contains(values []string, value string) bool { for _, v := range values { if v == value { return true } } return false }
- #12/gno.MemPackageType
- #13 MPUserAll
Result log
msg:0,success:true,log:,events:[]