Amounts management: cent, unit, and relative formats
Follows #131 (closed).
In the Ğ1 currency, the sources amounts are stored as integers for storage simplicity in nodes’ databases and in order to be able to re-evaluate the UD value.
In the end, we are dealing with amounts in cents in the backend and in units in the frontend.
We are constantly dealing with divisions or multiplication by 100 or UDValue (which is in cent format) between the front and the back. Currently, this management is spread all around the code for the money management.
The solution would be to have a helper in DuniterPy to take care of this issue.
We would need something in which we can:
- enter a value from the front specifying unit or UD: ie: specifying a tx amount from the CLI
- enter a value from the back: ie: source fetched from a node
- output the value in the three formats: cents, unit, relative: ie: for the frontend display
The best suitable structure for this problem is a class with methods:
- Use methods to specify what type of value is entered to be stored
- The value would be stored in cents
- Its access in unit or relative formats would divide it by
- This class should also take care of the float multiplication/division issue.
dataclassformat would be perfect for this case but it would requires that the minimum supported Python version is 3.7.
- Can or should we found a common rule to also include ĞTest and other currencies?