Skip to content
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

R4R: Sortable Decimal Bytes #5360

Merged
merged 10 commits into from
Dec 5, 2019
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-Authored-By: Jack Zampolin <jack.zampolin@gmail.com>
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

sunnya97 and jackzampolin authored Dec 3, 2019
commit aa97189b661a47f6be9b7e499844519be7f8ccf9
3 changes: 1 addition & 2 deletions types/decimal.go
Original file line number Diff line number Diff line change
@@ -560,7 +560,6 @@ func ValidSortableDec(dec Dec) bool {

// FormattingStringSortableBytes is the string used in Sprintf to left and right pad the sdk.Dec
// It adjusts based on the Precision constant
var FormattingStringSortableBytes = fmt.Sprintf("%%0%ds", Precision*2+1)

// Returns a byte slice representation of an sdk.Dec that can be sorted.
// Left and right pads with 0s so there are 18 digits to left and right of decimal point
@@ -569,7 +568,7 @@ func SortableDecBytes(dec Dec) []byte {
if !ValidSortableDec(dec) {
panic("dec must be within bounds")
}
return []byte(fmt.Sprintf(FormattingStringSortableBytes, dec.String()))
return []byte(fmt.Sprintf(fmt.Sprintf("%%0%ds", Precision*2+1), dec.String()))
}

//___________________________________________________________________________________