github.com/cosmos/cosmos-sdk@v0.50.10/x/authz/genesis.go (about)

     1  package authz
     2  
     3  import (
     4  	fmt "fmt"
     5  
     6  	cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
     7  )
     8  
     9  // NewGenesisState creates new GenesisState object
    10  func NewGenesisState(entries []GrantAuthorization) *GenesisState {
    11  	return &GenesisState{
    12  		Authorization: entries,
    13  	}
    14  }
    15  
    16  // ValidateGenesis check the given genesis state has no integrity issues
    17  func ValidateGenesis(data GenesisState) error {
    18  	for i, a := range data.Authorization {
    19  		if a.Grantee == "" {
    20  			return fmt.Errorf("authorization: %d, missing grantee", i)
    21  		}
    22  		if a.Granter == "" {
    23  			return fmt.Errorf("authorization: %d,missing granter", i)
    24  		}
    25  
    26  	}
    27  	return nil
    28  }
    29  
    30  // DefaultGenesisState - Return a default genesis state
    31  func DefaultGenesisState() *GenesisState {
    32  	return &GenesisState{}
    33  }
    34  
    35  var _ cdctypes.UnpackInterfacesMessage = GenesisState{}
    36  
    37  // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
    38  func (data GenesisState) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error {
    39  	for _, a := range data.Authorization {
    40  		err := a.UnpackInterfaces(unpacker)
    41  		if err != nil {
    42  			return err
    43  		}
    44  	}
    45  	return nil
    46  }
    47  
    48  // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
    49  func (msg GrantAuthorization) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error {
    50  	var a Authorization
    51  	return unpacker.UnpackAny(msg.Authorization, &a)
    52  }