2024-02-01 04:48:40 +00:00
|
|
|
package bond
|
|
|
|
|
2024-02-01 10:58:34 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
fmt "fmt"
|
|
|
|
|
|
|
|
sdkmath "cosmossdk.io/math"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2024-07-11 05:16:31 +00:00
|
|
|
// DefaultMaxBondAmountTokens are the default parameter values.
|
2024-07-30 05:32:54 +00:00
|
|
|
var DefaultMaxBondAmountTokens = sdkmath.NewInt(1000000000000) // 10^12 alnt
|
2024-02-01 10:58:34 +00:00
|
|
|
|
|
|
|
func NewParams(maxBondAmount sdk.Coin) Params {
|
|
|
|
return Params{MaxBondAmount: maxBondAmount}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultParams returns default module parameters
|
|
|
|
func DefaultParams() Params {
|
|
|
|
return NewParams(sdk.NewCoin(sdk.DefaultBondDenom, DefaultMaxBondAmountTokens))
|
|
|
|
}
|
|
|
|
|
2024-02-08 13:23:20 +00:00
|
|
|
// Validate checks that the parameters have valid values
|
|
|
|
func (p Params) Validate() error {
|
|
|
|
if err := validateMaxBondAmount(p.MaxBondAmount); err != nil {
|
|
|
|
return err
|
2024-02-01 10:58:34 +00:00
|
|
|
}
|
2024-02-08 13:23:20 +00:00
|
|
|
|
|
|
|
return nil
|
2024-02-01 10:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func validateMaxBondAmount(i interface{}) error {
|
|
|
|
v, ok := i.(sdk.Coin)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid parameter type: %T", i)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Amount.IsNegative() {
|
|
|
|
return errors.New("max bond amount must be positive")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|