-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
conversion: behavioural changes in
String
, MarshalText
and `Marsh…
…alJSON` (#144) This PR changes the way marshalling and unmarshalling behaves, in order to maximize compatibilty with `big.Int`: as in, maximize the chance that a 'drop in' replacement of `big.Int` for `uint256.Int` will work seamlessly. - `String()` - before this change, `String()` would return the integer in hexadecimal format. This PR changes it to instead return the input in decimal format, like `big.Int` does. - `MarshalText()` now returns the integer in decimal format, previously hexadecimal. - `MarshalJSON()` now returns the integer in decimal format, previously hexadecimal. - `UnmarshalText` now accepts either hex, `0x234` or `234`. Previously it accepted _only_ hex. - `UnmarshalJSON` now accepts either hex-string, `"0x234"`, dec-string `"234"` or naked numeric decimal `234`. Previously it accepted _only_ string-hex. JSON marshalling is, alas, not 100% compatible, since `big.Int` marshals to json numeric format: `{ Foo: 5}` as opposed to string-format: `{ Foo: "5" }`. The former is not ideal for large numbers, since platforms like javascript do not support arbitary large numbers, usually capped at `53` bits or so. TLDR; with this change, some output-formats change from Hex to Dec, but also some input-formats become more accepting. This change achieves better -- but not total -- compatibility with big.Int marshalling.
- Loading branch information
Showing
2 changed files
with
66 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters