-
Notifications
You must be signed in to change notification settings - Fork 10
/
poe.go
45 lines (40 loc) · 1.11 KB
/
poe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package types
import (
"sort"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)
func (t PoEContractType) ValidateBasic() error {
if t == PoEContractTypeUndefined {
return wasmtypes.ErrInvalid
}
if _, ok := PoEContractType_name[int32(t)]; !ok {
return wasmtypes.ErrNotFound
}
return nil
}
// PoEContractTypeFrom converts string representation to PoEContractType.
// Returns PoEContractTypeUndefined for unknown or misspelled values.
func PoEContractTypeFrom(s string) PoEContractType {
v, ok := PoEContractType_value[s]
if !ok {
return PoEContractTypeUndefined
}
return PoEContractType(v)
}
// IteratePoEContractTypes for each defined poe contract type the given callback is called deterministic.
// When the callback returns true the loop is aborted early
func IteratePoEContractTypes(cb func(tp PoEContractType) bool) {
names := make([]string, 0, len(PoEContractType_name)-1)
for _, v := range PoEContractType_name {
if v == PoEContractTypeUndefined.String() {
continue
}
names = append(names, v)
}
sort.Strings(names)
for _, v := range names {
if cb(PoEContractTypeFrom(v)) {
return
}
}
}