Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

utils.gno

1.58 Kb · 63 lines
 1package launchpad
 2
 3import (
 4	"math"
 5	"strconv"
 6	"strings"
 7
 8	ufmt "gno.land/p/nt/ufmt/v0"
 9)
10
11const (
12	MAX_INT64 = math.MaxInt64
13	MIN_INT64 = math.MinInt64
14)
15
16func buildConditionEventAttrs(conditionTokens string, conditionAmounts string) []string {
17	if conditionTokens == "" {
18		return []string{}
19	}
20
21	tokenPaths := strings.Split(conditionTokens, stringSplitterPad)
22	amounts := strings.Split(conditionAmounts, stringSplitterPad)
23	eventAttrs := make([]string, 0, len(tokenPaths)*2)
24
25	for index, tokenPath := range tokenPaths {
26		eventAttrs = append(eventAttrs, ufmt.Sprintf("conditionsTokens[%d]", index))
27		eventAttrs = append(eventAttrs, tokenPath+stringSplitterPad+amounts[index])
28	}
29
30	return eventAttrs
31}
32
33// parseProjectTierID parses a project tier ID into its project ID and duration.
34// Returns the project ID {tokenPath}:{createdHeight} and the duration of the project tier (30, 90, 180).
35func parseProjectTierID(projectTierID string) (string, int64) {
36	parts := strings.Split(projectTierID, ":")
37	if len(parts) != 3 {
38		panic(makeErrorWithDetails(
39			errInvalidData,
40			ufmt.Sprintf("(%s)", projectTierID),
41		))
42	}
43
44	projectID := parts[0] + ":" + parts[1]
45
46	tierDuration, err := strconv.ParseInt(parts[2], 10, 64)
47	if err != nil {
48		panic(makeErrorWithDetails(
49			errInvalidData,
50			ufmt.Sprintf("(%s)", projectTierID),
51		))
52	}
53
54	// Validate tier duration
55	if tierDuration != projectTier30 && tierDuration != projectTier90 && tierDuration != projectTier180 {
56		panic(makeErrorWithDetails(
57			errInvalidTier,
58			ufmt.Sprintf("pool type(%d) is not available", tierDuration),
59		))
60	}
61
62	return projectID, tierDuration
63}