-
Notifications
You must be signed in to change notification settings - Fork 23
/
genesis.go
36 lines (29 loc) · 916 Bytes
/
genesis.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
package types
import (
fmt "fmt"
"regexp"
)
// DefaultGenesis returns the default ssi genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
ChainNamespace: "",
Params: DefaultParams(),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
namespace := gs.ChainNamespace
regexPattern, err := regexp.Compile("^[a-zA-Z0-9-]*$") // Matches string containing whitespaces and tabs
if err != nil {
return err
}
maxChainNamespaceLength := 10
if len(namespace) > maxChainNamespaceLength {
return fmt.Errorf("chain namespace shouldn't shouldn't be more than 10, namespace recieved %s", namespace)
}
if !regexPattern.MatchString(namespace) && len(namespace) != 0 {
return fmt.Errorf("chain namespace should be in alphanumeric format, namespace recieved %s", namespace)
}
return nil
}