-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
types: Dec.MarshalJSON now marshals as a normal decimal string #2506
Conversation
This is failing because we for some reason are MarshalJSON'ing decimals when used as parameter keys. That should be fixed in a separate PR. |
types/decimal.go
Outdated
bzWDec[len(bz)-10] = byte('.') | ||
copy(bzWDec[len(bz)-9:], bz[len(bz)-10:]) | ||
} | ||
return json.Marshal(string(bzWDec)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this logic already exists using Decimal.String()
- why are we not reusing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh woops, didn't see that lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think this implementation is more efficient (albeit harder to grok). I'd actually propose making a follow-up issue to compare efficiencies via benchmarks and converge on using one or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo - If I had to guess I'd say you're correct why don't we:
- Replace the
.String()
code with your new updated logic - Use
.String()
in JSON Marshalling here - copy the old code into a #postlaunch issue for later benchmarking
:)
how does that sound?
Is this R4R? |
Its ready to merge once I replace the current string implementation with my (more efficient looking) implementation written here. |
Codecov Report
@@ Coverage Diff @@
## develop #2506 +/- ##
========================================
Coverage 60.28% 60.28%
========================================
Files 150 150
Lines 8589 8589
========================================
Hits 5178 5178
Misses 3067 3067
Partials 344 344 |
…-sdk into dev/change_dec_marshaljson
types/decimal.go
Outdated
copy(bzWDec[2+(10-len(bz)):], bz) | ||
} else { | ||
// len(bz) + 1 to account for the decimal point that is being added | ||
bzWDec = make([]byte, len(bz)+1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store len(bz)
in a variable
types/decimal.go
Outdated
bzWDec[0] = byte('0') | ||
bzWDec[1] = byte('.') | ||
// set relevant digits to 0 | ||
for i := 0; i < 10-len(bz); i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store len(bz)
in a variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
Closes #2475
This implementation has sub-optimal efficiency, should re-use memory allocations in unmarshalling. However this is only called for UI purports, so not really a big deal if its a tiny bit slower.
Targeted PR against correct branch (see CONTRIBUTING.md)
Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
Wrote tests
Updated relevant documentation (
docs/
) - no encoding docs atmAdded entries in
PENDING.md
with issue #rereviewed
Files changed
in the github PR explorerFor Admin Use: