github.com/Finschia/finschia-sdk@v0.48.1/simapp/genesis_account.go (about)

     1  package simapp
     2  
     3  import (
     4  	"errors"
     5  
     6  	sdk "github.com/Finschia/finschia-sdk/types"
     7  	authtypes "github.com/Finschia/finschia-sdk/x/auth/types"
     8  )
     9  
    10  var _ authtypes.GenesisAccount = (*SimGenesisAccount)(nil)
    11  
    12  // SimGenesisAccount defines a type that implements the GenesisAccount interface
    13  // to be used for simulation accounts in the genesis state.
    14  type SimGenesisAccount struct {
    15  	*authtypes.BaseAccount
    16  
    17  	// vesting account fields
    18  	OriginalVesting  sdk.Coins `json:"original_vesting" yaml:"original_vesting"`   // total vesting coins upon initialization
    19  	DelegatedFree    sdk.Coins `json:"delegated_free" yaml:"delegated_free"`       // delegated vested coins at time of delegation
    20  	DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"` // delegated vesting coins at time of delegation
    21  	StartTime        int64     `json:"start_time" yaml:"start_time"`               // vesting start time (UNIX Epoch time)
    22  	EndTime          int64     `json:"end_time" yaml:"end_time"`                   // vesting end time (UNIX Epoch time)
    23  
    24  	// module account fields
    25  	ModuleName        string   `json:"module_name" yaml:"module_name"`               // name of the module account
    26  	ModulePermissions []string `json:"module_permissions" yaml:"module_permissions"` // permissions of module account
    27  }
    28  
    29  // Validate checks for errors on the vesting and module account parameters
    30  func (sga SimGenesisAccount) Validate() error {
    31  	if !sga.OriginalVesting.IsZero() {
    32  		if sga.StartTime >= sga.EndTime {
    33  			return errors.New("vesting start-time cannot be before end-time")
    34  		}
    35  	}
    36  
    37  	if sga.ModuleName != "" {
    38  		ma := authtypes.ModuleAccount{
    39  			BaseAccount: sga.BaseAccount, Name: sga.ModuleName, Permissions: sga.ModulePermissions,
    40  		}
    41  		if err := ma.Validate(); err != nil {
    42  			return err
    43  		}
    44  	}
    45  
    46  	return sga.BaseAccount.Validate()
    47  }