dep update

...

...
This commit is contained in:
rigelrozanski 2018-03-26 16:53:55 +02:00
parent 1df21e0fb6
commit e25b78055b
5 changed files with 39 additions and 15 deletions

5
Gopkg.lock generated
View File

@ -145,10 +145,7 @@
[[projects]]
name = "github.com/magiconair/properties"
packages = [
".",
"assert"
]
packages = ["."]
revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6"
version = "v1.7.6"

View File

@ -1,6 +1,7 @@
package types
import (
"fmt"
"math/big"
"strconv"
"strings"
@ -79,7 +80,7 @@ func NewRat(num int64, denom ...int64) Rat {
}
}
//NewFromDecimal - create a rational from decimal string or integer string
// create a rational from decimal string or integer string
func NewRatFromDecimal(decimalStr string) (f Rat, err Error) {
// first extract any negative symbol
@ -148,14 +149,16 @@ func (r Rat) Sub(r2 Rat) Rat { return ToRat(new(big.Rat).Sub(r.GetRat(), r2.G
//func (r Rat) Sub(r2 Rat) Rat { return Rat{new(big.Rat).Sub(r.Rat, r2.GetRat())} } // Sub - subtraction
//func (r Rat) String() string { return fmt.Sprintf("%v/%v", r.Num(), r.Denom()) } // Sub - subtraction
var zero = big.NewInt(0)
var one = big.NewInt(1)
var two = big.NewInt(2)
var five = big.NewInt(5)
var nFive = big.NewInt(-5)
var ten = big.NewInt(10)
var (
zero = big.NewInt(0)
one = big.NewInt(1)
two = big.NewInt(2)
five = big.NewInt(5)
nFive = big.NewInt(-5)
ten = big.NewInt(10)
)
// EvaluateBig - evaluate the rational using bankers rounding
// evaluate the rational using bankers rounding
func (r Rat) EvaluateBig() *big.Int {
num := r.GetRat().Num()
@ -185,17 +188,25 @@ func (r Rat) EvaluateBig() *big.Int {
return d
}
// Evaluate - evaluate the rational using bankers rounding
// evaluate the rational using bankers rounding
func (r Rat) Evaluate() int64 {
return r.EvaluateBig().Int64()
}
// Round - round Rat with the provided precisionFactor
// round Rat with the provided precisionFactor
func (r Rat) Round(precisionFactor int64) Rat {
rTen := ToRat(new(big.Rat).Mul(r.GetRat(), big.NewRat(precisionFactor, 1)))
return ToRat(big.NewRat(rTen.Evaluate(), precisionFactor))
}
// TODO panic if negative or if totalDigits < len(initStr)???
// evaluate as an integer and return left padded string
func (r Rat) ToLeftPadded(totalDigits int8) string {
intStr := r.EvaluateBig().String()
fcode := `%0` + strconv.Itoa(int(totalDigits)) + `s`
return fmt.Sprintf(fcode, intStr)
}
//___________________________________________________________________________________
// Hack to just use json.Marshal for everything until

View File

@ -192,6 +192,20 @@ func TestRound(t *testing.T) {
}
}
func TestToLeftPaddedString(t *testing.T) {
tests := []struct {
rat Rat
digits int8
res string
}{
{NewRat(100, 3), 8, "00000033"},
}
for _, tc := range tests {
assert.Equal(t, tc.res, tc.rat.ToLeftPadded(tc.digits))
}
}
//func TestZeroSerializationJSON(t *testing.T) {
//r := NewRat(0, 1)
//err := r.UnmarshalJSON([]byte(`"0/1"`))

View File

@ -37,7 +37,7 @@ func (k Keeper) Tick(ctx sdk.Context) (change []*abci.Validator, err error) {
func (k Keeper) processProvisions(ctx sdk.Context) {
pool := k.GetPool(ctx)
pool.Inflation = k.nextInflation(ctx).Round(precision) //TODO make this number a const somewhere?
pool.Inflation = k.nextInflation(ctx).Round(precision)
// Because the validators hold a relative bonded share (`GlobalStakeShare`), when
// more bonded tokens are added proportionally to all validators the only term

View File

@ -16,6 +16,8 @@ type Params struct {
BondDenom string `json:"bond_denom"` // bondable coin denomination
}
// XXX do we want to allow for default params even or do we want to enforce that you
// need to be explicit about defining all params in genesis?
func defaultParams() Params {
return Params{
InflationRateChange: sdk.NewRat(13, 100),