-
Notifications
You must be signed in to change notification settings - Fork 0
/
staking.go
66 lines (49 loc) · 1.29 KB
/
staking.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package types
import (
"math/big"
)
type BondStatus int32
// PowerReduction is the amount of staking tokens required for 1 unit of consensus-engine power
var PowerReduction = NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(6), nil))
func TokensToConsensusPower(tokens Int) int64 {
return (tokens.Quo(PowerReduction)).Int64()
}
// TokensFromConsensusPower - convert input power to tokens
func TokensFromConsensusPower(power int64) Int {
return NewInt(power).Mul(PowerReduction)
}
const (
// default bond denomination
DefaultBondDenom = "WLK"
ValidatorUpdateDelay int64 = 1
Unbonded BondStatus = 1
Unbonding BondStatus = 2
Bonded BondStatus = 3
BondStatusUnbonded = "Unbonded"
BondStatusUnbonding = "Unbonding"
BondStatusBonded = "Bonded"
BondStatusAll = "all"
)
var (
ChainCoinDenom = DefaultBondDenom
)
func SetCoinDenom(denom string) {
ChainCoinDenom = denom
}
// Equal compares two BondStatus instances
func (b BondStatus) Equal(b2 BondStatus) bool {
return byte(b) == byte(b2)
}
// String implements the Stringer interface for BondStatus.
func (b BondStatus) String() string {
switch b {
case Unbonded:
return BondStatusUnbonded
case Unbonding:
return BondStatusUnbonding
case Bonded:
return BondStatusBonded
default:
panic("invalid bond status")
}
}