-
Notifications
You must be signed in to change notification settings - Fork 555
/
params.go
45 lines (36 loc) · 1.2 KB
/
params.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 (
"fmt"
"slices"
"strings"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
)
// DefaultAllowedClients are the default clients for the AllowedClients parameter.
var DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Localhost}
// NewParams creates a new parameter configuration for the ibc client module
func NewParams(allowedClients ...string) Params {
return Params{
AllowedClients: allowedClients,
}
}
// DefaultParams is the default parameter configuration for the ibc-client module.
func DefaultParams() Params {
return NewParams(DefaultAllowedClients...)
}
// Validate all ibc-client module parameters
func (p Params) Validate() error {
return validateClients(p.AllowedClients)
}
// IsAllowedClient checks if the given client type is registered on the allowlist.
func (p Params) IsAllowedClient(clientType string) bool {
return slices.Contains(p.AllowedClients, clientType)
}
// validateClients checks that the given clients are not blank.
func validateClients(clients []string) error {
for i, clientType := range clients {
if strings.TrimSpace(clientType) == "" {
return fmt.Errorf("client type %d cannot be blank", i)
}
}
return nil
}