2018-05-09 18:39:14 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2019-02-13 15:01:50 -08:00
|
|
|
"math/big"
|
2018-05-09 18:39:14 -07:00
|
|
|
)
|
|
|
|
|
2019-02-13 15:01:50 -08:00
|
|
|
// staking constants
|
2018-05-09 18:39:14 -07:00
|
|
|
const (
|
2019-02-13 15:01:50 -08:00
|
|
|
|
|
|
|
// default bond denomination
|
|
|
|
DefaultBondDenom = "stake"
|
|
|
|
|
2019-06-12 08:57:47 -07:00
|
|
|
// Delay, in blocks, between when validator updates are returned to the
|
|
|
|
// consensus-engine and when they are applied. For example, if
|
|
|
|
// ValidatorUpdateDelay is set to X, and if a validator set update is
|
|
|
|
// returned with new validators at the end of block 10, then the new
|
|
|
|
// validators are expected to sign blocks beginning at block 11+X.
|
|
|
|
//
|
|
|
|
// This value is constant as this should not change without a hard fork.
|
|
|
|
// For Tendermint this should be set to 1 block, for more details see:
|
|
|
|
// https://tendermint.com/docs/spec/abci/apps.html#endblock
|
2019-02-13 15:01:50 -08:00
|
|
|
ValidatorUpdateDelay int64 = 1
|
2018-05-09 18:39:14 -07:00
|
|
|
)
|
|
|
|
|
2019-06-12 08:57:47 -07:00
|
|
|
// PowerReduction is the amount of staking tokens required for 1 unit of consensus-engine power
|
2019-02-13 15:01:50 -08:00
|
|
|
var PowerReduction = NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(6), nil))
|
|
|
|
|
2019-06-12 08:57:47 -07:00
|
|
|
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
|
|
|
|
func TokensToConsensusPower(tokens Int) int64 {
|
2019-02-21 09:35:55 -08:00
|
|
|
return (tokens.Quo(PowerReduction)).Int64()
|
2019-02-13 15:01:50 -08:00
|
|
|
}
|
|
|
|
|
2019-06-12 08:57:47 -07:00
|
|
|
// TokensFromConsensusPower - convert input power to tokens
|
|
|
|
func TokensFromConsensusPower(power int64) Int {
|
2019-02-13 15:01:50 -08:00
|
|
|
return NewInt(power).Mul(PowerReduction)
|
|
|
|
}
|
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
// BondStatus is the status of a validator
|
|
|
|
type BondStatus byte
|
2018-05-09 18:39:14 -07:00
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
// staking constants
|
|
|
|
const (
|
|
|
|
Unbonded BondStatus = 0x00
|
|
|
|
Unbonding BondStatus = 0x01
|
|
|
|
Bonded BondStatus = 0x02
|
2018-05-09 18:39:14 -07:00
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
BondStatusUnbonded = "Unbonded"
|
|
|
|
BondStatusUnbonding = "Unbonding"
|
|
|
|
BondStatusBonded = "Bonded"
|
|
|
|
)
|
2018-05-09 18:39:14 -07:00
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
// Equal compares two BondStatus instances
|
|
|
|
func (b BondStatus) Equal(b2 BondStatus) bool {
|
|
|
|
return byte(b) == byte(b2)
|
2018-05-09 18:39:14 -07:00
|
|
|
}
|
2018-08-31 17:01:23 -07:00
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
// String implements the Stringer interface for BondStatus.
|
|
|
|
func (b BondStatus) String() string {
|
|
|
|
switch b {
|
|
|
|
case 0x00:
|
|
|
|
return BondStatusUnbonded
|
|
|
|
case 0x01:
|
|
|
|
return BondStatusUnbonding
|
|
|
|
case 0x02:
|
|
|
|
return BondStatusBonded
|
|
|
|
default:
|
|
|
|
panic("invalid bond status")
|
|
|
|
}
|
2018-09-17 20:02:15 -07:00
|
|
|
}
|