-
Notifications
You must be signed in to change notification settings - Fork 12
Description
During the review of #573 @andrevmatos found a potential problem: our losslessParse() function, which is used for parsing JSON API responses, only converts numbers of the type string into BigNumber. This is because the Raiden API does return all numbers as strings. However the PFS API uses the JSON number type for numbers. This is no problem at the moment, because we don't use the numbers from the PFS API, but could be one in the future. We should use a library for parsing.
André's comment from #573:
This
losslessParsemay work only if the BNs are stringified on the JSONs (since thisrevivefunction fromJSON.parseis called only after the number already got parsed as such), while it seems the current PFS implementation encodes thecapacityand other BNs as JSONnumber. This may only be working now if the numbers on your test were small (i.e. < 2^53).
We had this issue on the LC, and ended up usingjson-bigintlib to parse these JSONs. Check here for our implementation.
Notice you need to use a proper decoder/schema validator if you go the way we did, since it'll ensure these values are kept as
strings, or use it with yourreviverfunction after using the lib to ensure the BNs are kept as strings orbigintor whatever.. We already had the schemas in place, so went with it, but you can use the reviver as well if you don't care that much with the typesafety there.