github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/types/staking.go (about) 1 package types 2 3 import ( 4 "math/big" 5 ) 6 7 // staking constants 8 const ( 9 10 // default bond denomination 11 DefaultBondDenom = "fibo" 12 13 // Delay, in blocks, between when validator updates are returned to the 14 // consensus-engine and when they are applied. For example, if 15 // ValidatorUpdateDelay is set to X, and if a validator set update is 16 // returned with new validators at the end of block 10, then the new 17 // validators are expected to sign blocks beginning at block 11+X. 18 // 19 // This value is constant as this should not change without a hard fork. 20 // For Tendermint this should be set to 1 block, for more details see: 21 // https://tendermint.com/docs/spec/abci/apps.html#endblock 22 ValidatorUpdateDelay int64 = 1 23 ) 24 25 // PowerReduction is the amount of staking tokens required for 1 unit of consensus-engine power 26 var PowerReduction = NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(Precision), nil)) 27 28 // TokensToConsensusPower - convert input tokens to potential consensus-engine power 29 func TokensToConsensusPower(tokens Int) int64 { 30 return (tokens.Quo(PowerReduction)).Int64() 31 } 32 33 // TokensFromConsensusPower - convert input power to tokens 34 func TokensFromConsensusPower(power int64) Int { 35 return NewInt(power).Mul(PowerReduction) 36 } 37 38 // BondStatus is the status of a validator 39 type BondStatus byte 40 41 // staking constants 42 const ( 43 Unbonded BondStatus = 0x00 44 Unbonding BondStatus = 0x01 45 Bonded BondStatus = 0x02 46 47 BondStatusUnbonded = "Unbonded" 48 BondStatusUnbonding = "Unbonding" 49 BondStatusBonded = "Bonded" 50 ) 51 52 // Equal compares two BondStatus instances 53 func (b BondStatus) Equal(b2 BondStatus) bool { 54 return byte(b) == byte(b2) 55 } 56 57 // String implements the Stringer interface for BondStatus. 58 func (b BondStatus) String() string { 59 switch b { 60 case 0x00: 61 return BondStatusUnbonded 62 case 0x01: 63 return BondStatusUnbonding 64 case 0x02: 65 return BondStatusBonded 66 default: 67 panic("invalid bond status") 68 } 69 }