github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/erc20/types/params.go (about) 1 package types 2 3 import ( 4 "fmt" 5 6 "gopkg.in/yaml.v2" 7 8 "github.com/fibonacci-chain/fbc/x/params" 9 ) 10 11 const ( 12 // DefaultParamspace for params keeper 13 DefaultParamspace = ModuleName 14 15 DefaultIbcTimeout = uint64(86400000000000) // 1 day 16 DefaultAutoDeploymentEnabled = false 17 ) 18 19 var ( 20 KeyEnableAutoDeployment = []byte("EnableAutoDeployment") 21 KeyIbcTimeout = []byte("IbcTimeout") 22 ) 23 24 // ParamKeyTable returns the parameter key table. 25 func ParamKeyTable() params.KeyTable { 26 return params.NewKeyTable().RegisterParamSet(&Params{}) 27 } 28 29 // Params defines the module parameters 30 type Params struct { 31 EnableAutoDeployment bool `json:"enable_auto_deployment" yaml:"enable_auto_deployment"` 32 IbcTimeout uint64 `json:"ibc_timeout" yaml:"ibc_timeout"` 33 } 34 35 // NewParams creates a new Params instance 36 func NewParams(enableAutoDeployment bool, ibcTimeout uint64) Params { 37 return Params{ 38 EnableAutoDeployment: enableAutoDeployment, 39 IbcTimeout: ibcTimeout, 40 } 41 } 42 43 // DefaultParams returns default parameters 44 func DefaultParams() Params { 45 return Params{ 46 EnableAutoDeployment: DefaultAutoDeploymentEnabled, 47 IbcTimeout: DefaultIbcTimeout, 48 } 49 } 50 51 // String implements the fmt.Stringer interface 52 func (p Params) String() string { 53 out, _ := yaml.Marshal(p) 54 return string(out) 55 } 56 57 // ParamSetPairs returns the parameter set pairs. 58 func (p *Params) ParamSetPairs() params.ParamSetPairs { 59 return params.ParamSetPairs{ 60 params.NewParamSetPair(KeyEnableAutoDeployment, &p.EnableAutoDeployment, validateBool), 61 params.NewParamSetPair(KeyIbcTimeout, &p.IbcTimeout, validateUint64), 62 } 63 } 64 65 // Validate performs basic validation on erc20 parameters. 66 func (p Params) Validate() error { 67 if err := validateUint64(p.IbcTimeout); err != nil { 68 return err 69 } 70 return nil 71 } 72 73 func validateUint64(i interface{}) error { 74 if _, ok := i.(uint64); !ok { 75 return fmt.Errorf("invalid parameter type: %T", i) 76 } 77 return nil 78 } 79 80 func validateBool(i interface{}) error { 81 _, ok := i.(bool) 82 if !ok { 83 return fmt.Errorf("invalid parameter type: %T", i) 84 } 85 return nil 86 }