Skip to content
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

Smart Contracts: Safe floating point maths + automatic amount conversion to 10^8 #973

Conversation

bchamagne
Copy link
Member

@bchamagne bchamagne commented Apr 5, 2023

Description

This PR is based on #967. To be rebased as soon as it is merged.

  1. User may now code Contract.add_uco_transfer to: "...", amount: 1 to transfer 1 UCO (before he/she had to specify amount: 100000000 to send 1 UCO. Makes the language friendlier.
  2. Floating points mathematics are now done in BigInt so there is no floating point precision issue.
  3. Since we use BigInt for maths, we loose the types of the numbers (1 + 1 == 2.0). To address this inconvenience, I updated the library to have String.from_number/1 and String.to_number/1 instead of String.from_float/1, String.from_int/1, String.to_float/1, String.to_int/1.

Fixes #893

ps: I suggest to ignore test/archethic/contracts/interpreter/condition_interpreter_test.exs when reviewing. This is just tests adaption due to the function being stricter than before (it is a good thing).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Unit tests ✔️
Manual tests: ❔

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@bchamagne bchamagne added the smart contracts Involve smart contracts label Apr 5, 2023
@bchamagne bchamagne linked an issue Apr 20, 2023 that may be closed by this pull request
@samuelmanzanera samuelmanzanera merged commit 1f5d9d4 into archethic-foundation:926-get-calls-refactor Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smart contracts Involve smart contracts
Projects
Status: Done 🍻
Development

Successfully merging this pull request may close these issues.

Transaction amount should verify it is BigInt
3 participants