2018-06-26 19:00:12 -07:00
|
|
|
package types
|
2018-05-12 15:22:59 -07:00
|
|
|
|
|
|
|
import (
|
2018-05-18 15:57:47 -07:00
|
|
|
"bytes"
|
2018-08-21 08:32:54 -07:00
|
|
|
"fmt"
|
2018-08-12 00:33:48 -07:00
|
|
|
"time"
|
2018-05-18 15:57:47 -07:00
|
|
|
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-08-31 02:03:43 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/params"
|
2018-05-12 15:22:59 -07:00
|
|
|
)
|
|
|
|
|
2018-10-05 10:56:17 -07:00
|
|
|
const (
|
|
|
|
// defaultUnbondingTime reflects three weeks in seconds as the default
|
|
|
|
// unbonding time.
|
|
|
|
defaultUnbondingTime time.Duration = 60 * 60 * 24 * 3 * time.Second
|
|
|
|
|
|
|
|
// Delay, in blocks, between when validator updates are returned to Tendermint and when they are applied
|
|
|
|
// For example, if this is 0, the validator set at the end of a block will sign the next block, or
|
|
|
|
// if this is 1, the validator set at the end of a block will sign the block after the next.
|
|
|
|
// Constant as this should not change without a hard fork.
|
|
|
|
ValidatorUpdateDelay int64 = 1
|
|
|
|
)
|
2018-07-03 21:21:36 -07:00
|
|
|
|
2018-09-17 08:28:13 -07:00
|
|
|
// nolint - Keys for parameter access
|
2018-09-27 11:52:29 -07:00
|
|
|
var (
|
2018-10-19 11:36:00 -07:00
|
|
|
KeyUnbondingTime = []byte("UnbondingTime")
|
|
|
|
KeyMaxValidators = []byte("MaxValidators")
|
|
|
|
KeyBondDenom = []byte("BondDenom")
|
2018-09-17 08:28:13 -07:00
|
|
|
)
|
2018-08-31 02:03:43 -07:00
|
|
|
|
2018-10-10 13:01:30 -07:00
|
|
|
var _ params.ParamSet = (*Params)(nil)
|
2018-10-06 06:50:58 -07:00
|
|
|
|
2018-05-12 15:22:59 -07:00
|
|
|
// Params defines the high level settings for staking
|
|
|
|
type Params struct {
|
2018-08-12 00:33:48 -07:00
|
|
|
UnbondingTime time.Duration `json:"unbonding_time"`
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-05-12 15:22:59 -07:00
|
|
|
MaxValidators uint16 `json:"max_validators"` // maximum number of validators
|
|
|
|
BondDenom string `json:"bond_denom"` // bondable coin denomination
|
|
|
|
}
|
|
|
|
|
2018-10-10 13:01:30 -07:00
|
|
|
// Implements params.ParamSet
|
2018-10-06 06:50:58 -07:00
|
|
|
func (p *Params) KeyValuePairs() params.KeyValuePairs {
|
|
|
|
return params.KeyValuePairs{
|
2018-09-17 08:28:13 -07:00
|
|
|
{KeyUnbondingTime, &p.UnbondingTime},
|
|
|
|
{KeyMaxValidators, &p.MaxValidators},
|
|
|
|
{KeyBondDenom, &p.BondDenom},
|
2018-08-31 02:03:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-03 21:21:36 -07:00
|
|
|
// Equal returns a boolean determining if two Param types are identical.
|
2018-06-26 19:00:12 -07:00
|
|
|
func (p Params) Equal(p2 Params) bool {
|
2018-11-04 18:28:38 -08:00
|
|
|
bz1 := MsgCdc.MustMarshalBinaryLengthPrefixed(&p)
|
|
|
|
bz2 := MsgCdc.MustMarshalBinaryLengthPrefixed(&p2)
|
2018-05-18 15:57:47 -07:00
|
|
|
return bytes.Equal(bz1, bz2)
|
2018-05-12 15:22:59 -07:00
|
|
|
}
|
|
|
|
|
2018-07-03 21:21:36 -07:00
|
|
|
// DefaultParams returns a default set of parameters.
|
2018-05-25 07:17:49 -07:00
|
|
|
func DefaultParams() Params {
|
2018-05-12 15:22:59 -07:00
|
|
|
return Params{
|
2018-10-19 11:36:00 -07:00
|
|
|
UnbondingTime: defaultUnbondingTime,
|
|
|
|
MaxValidators: 100,
|
|
|
|
BondDenom: "steak",
|
2018-05-12 15:22:59 -07:00
|
|
|
}
|
|
|
|
}
|
2018-08-21 08:32:54 -07:00
|
|
|
|
|
|
|
// HumanReadableString returns a human readable string representation of the
|
|
|
|
// parameters.
|
|
|
|
func (p Params) HumanReadableString() string {
|
|
|
|
|
2018-10-19 11:36:00 -07:00
|
|
|
resp := "Params \n"
|
2018-08-21 08:32:54 -07:00
|
|
|
resp += fmt.Sprintf("Unbonding Time: %s\n", p.UnbondingTime)
|
|
|
|
resp += fmt.Sprintf("Max Validators: %d: \n", p.MaxValidators)
|
|
|
|
resp += fmt.Sprintf("Bonded Coin Denomination: %s\n", p.BondDenom)
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal the current staking params value from store key or panic
|
2018-09-13 11:17:32 -07:00
|
|
|
func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params {
|
2018-08-21 08:32:54 -07:00
|
|
|
params, err := UnmarshalParams(cdc, value)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return params
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal the current staking params value from store key
|
2018-09-13 11:17:32 -07:00
|
|
|
func UnmarshalParams(cdc *codec.Codec, value []byte) (params Params, err error) {
|
2018-11-04 18:28:38 -08:00
|
|
|
err = cdc.UnmarshalBinaryLengthPrefixed(value, ¶ms)
|
2018-08-21 08:32:54 -07:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|