h-REA / hREA

A ValueFlows / REA economic network coordination system implemented on Holochain and with supplied Javascript GraphQL libraries
https://docs.hrea.io
Other
142 stars 15 forks source link

Update zome API structs to use strings for passing numerical values, avoiding potential value truncation #382

Open pospi opened 1 year ago

pospi commented 1 year ago

In 81ad8e65 a temporary measure was added for compatibility with the latest VF-GraphQL spec without requiring extensive updates to the zome APIs. To prevent any possible numerical truncation, the new Decimal type should be de/serialized as a string rather than a JavaScript number.

This will require a new externally-facing variant of the QuantityValue struct where has_numerical_value is a String. Custom serialization logic will need to be added to convert to/from the external string-based representation to an internal Rust format that is able to handle accurate arbitrary-precision decimal math. There are probably crates that integrate with Serde to do this automatically, but some investigation needs to be made.

Filing this as a bug since until these changes are made, very large values (in excess of 2^1024-1) will be truncated before sending. Since such use-cases are likely to be very rare, we can consider this a low priority issue.

pospi commented 1 year ago

(Probably best to add that I'm unclear on the details re maximum expressible values in JS; could equally be 2^53 - 1 or some other value depending on floating point storage overhead and script engine.)