New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go-kosu: update scaling methods to be consistent #243
Changes from all commits
4fe6611
cf6a4b2
dfaf411
8a916aa
9c82c07
92364bc
c36d07a
File filter...
Jump to…
| @@ -79,15 +79,15 @@ func posterIterator(app *App, totalBalance *big.Int) func(string, *types.Poster) | ||
| // calculates a poster's period limit based on their balance and the total poster balance | ||
| func posterLimit(periodLimit uint64, posterBalance, totalBalance *big.Int) uint64 { | ||
| // copy periodLimit (pl), posterBalance (pb), totalBalance (tb) | ||
| var pl, pb, tb big.Int | ||
| pl, pb, tb := &big.Int{}, &big.Int{}, &big.Int{} | ||
|
This conversation was marked as resolved
by gchaincl
hrharder
Author
Member
|
||
| pl.SetUint64(periodLimit) | ||
| pb.Set(posterBalance) | ||
| tb.Set(totalBalance) | ||
|
|
||
| // limit = (posterBalance / totalBalance) * periodLimit | ||
| limit := big.NewInt(0) | ||
| limit.Mul(&pl, &pb) | ||
| limit.Div(limit, &tb) | ||
| limit.Mul(pl, pb) | ||
| limit.Div(limit, tb) | ||
|
|
||
| if !limit.IsUint64() { | ||
| return math.MaxUint64 | ||
| @@ -102,15 +102,18 @@ func scaleBalance(balance *big.Int) int64 { | ||
| return int64(0) | ||
| } | ||
|
|
||
| scaled := &big.Rat{} | ||
| divisor := &big.Int{} | ||
| scaled := &big.Int{} | ||
| ether := &big.Int{} | ||
| scaled.Set(balance) | ||
|
|
||
| // scale balance by 10**18 (base units for KOSU) | ||
| // linter disabled for outdated gosec rule | ||
| // nolint:gosec | ||
| divisor = divisor.Exp(big.NewInt(10), big.NewInt(18), nil) | ||
| scaled.SetFrac(balance, divisor) | ||
| ether.Exp(big.NewInt(10), big.NewInt(18), big.NewInt(0)) | ||
| scaled.Div(balance, ether) | ||
|
|
||
| res, _ := scaled.Float64() | ||
| power := math.Floor(res) | ||
| return int64(power) | ||
| if !scaled.IsInt64() { | ||
| return math.MaxInt64 | ||
|
This conversation was marked as resolved
by gchaincl
hrharder
Author
Member
|
||
| } | ||
| return scaled.Int64() | ||
| } | ||
what's the difference between this and using non-pointers ?