-
Notifications
You must be signed in to change notification settings - Fork 206
/
proposal.go
49 lines (42 loc) · 1.39 KB
/
proposal.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
46
47
48
49
package types
import (
fmt "fmt"
"strings"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
func checkSpecProposal(spec Spec) error {
if len(strings.TrimSpace(spec.Name)) == 0 {
return sdkerrors.Wrap(ErrBlankSpecName, "spec name cannot be blank")
}
if len(strings.TrimSpace(spec.Index)) == 0 {
return sdkerrors.Wrap(ErrBlankSpecName, "spec index cannot be blank")
}
if len(spec.Apis) == 0 {
return sdkerrors.Wrap(ErrEmptyApis, "api list cannot be empty")
}
checkUnique := map[string]bool{}
for i, api := range spec.Apis {
if len(strings.TrimSpace(api.Name)) == 0 {
return sdkerrors.Wrap(ErrBlankApiName, "api name cannot be blank")
}
if _, ok := checkUnique[api.Name]; ok {
return sdkerrors.Wrap(ErrDuplicateApiName, fmt.Sprintf("api name must be unique: %s", api.Name))
}
if len(api.ApiInterfaces) == 0 {
return sdkerrors.Wrap(ErrBlankApiName, fmt.Sprintf("api interface cannot be empty at spec:%s, api %d", spec.Name, i))
}
checkUnique[api.Name] = true
}
return nil
}
func stringSpec(spec Spec, b strings.Builder) strings.Builder {
b.WriteString(fmt.Sprintf(` Spec name:
Name: %s, Spec index: %s, Enabled: %t, Apis: %d
`, spec.Name, spec.Index, spec.Enabled, len(spec.Apis)))
for _, api := range spec.Apis {
b.WriteString(fmt.Sprintf(` Api:
Name: %s, Enabled: %t, ComputeUntis: %d
`, api.Name, api.Enabled, api.ComputeUnits))
}
return b
}