github.com/Finschia/finschia-sdk@v0.48.1/x/capability/types/genesis.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // DefaultIndex is the default capability global index
     9  const DefaultIndex uint64 = 1
    10  
    11  // DefaultGenesis returns the default Capability genesis state
    12  func DefaultGenesis() *GenesisState {
    13  	return &GenesisState{
    14  		Index:  DefaultIndex,
    15  		Owners: []GenesisOwners{},
    16  	}
    17  }
    18  
    19  // Validate performs basic genesis state validation returning an error upon any
    20  // failure.
    21  func (gs GenesisState) Validate() error {
    22  	// NOTE: index must be greater than 0
    23  	if gs.Index == 0 {
    24  		return fmt.Errorf("capability index must be non-zero")
    25  	}
    26  
    27  	for _, genOwner := range gs.Owners {
    28  		if len(genOwner.IndexOwners.Owners) == 0 {
    29  			return fmt.Errorf("empty owners in genesis")
    30  		}
    31  
    32  		// all exported existing indices must be between [1, gs.Index)
    33  		if genOwner.Index == 0 || genOwner.Index >= gs.Index {
    34  			return fmt.Errorf("owners exist for index %d outside of valid range: %d-%d", genOwner.Index, 1, gs.Index-1)
    35  		}
    36  
    37  		for _, owner := range genOwner.IndexOwners.Owners {
    38  			if strings.TrimSpace(owner.Module) == "" {
    39  				return fmt.Errorf("owner's module cannot be blank: %s", owner)
    40  			}
    41  
    42  			if strings.TrimSpace(owner.Name) == "" {
    43  				return fmt.Errorf("owner's name cannot be blank: %s", owner)
    44  			}
    45  		}
    46  	}
    47  
    48  	return nil
    49  }