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

242 - unsafe integer cast for BalanceConversion's StaticLookUp implementation #256

Merged
merged 2 commits into from
Feb 14, 2023

Conversation

b-yap
Copy link
Contributor

@b-yap b-yap commented Feb 13, 2023

This is item #5 of #242
if conversion rate is too big for i64, set it to what its max is.
if the i64 value reaches negative, make it zero for u128.

^ Unless that's the wrong approach?

@b-yap b-yap force-pushed the 242-LIP-01_unsafe_integer_cast branch from a8ea7cc to 0fb72a2 Compare February 13, 2023 11:53
if the i64 value reaches negative, make it zero for u128
@b-yap b-yap force-pushed the 242-LIP-01_unsafe_integer_cast branch from 0fb72a2 to 5bdc044 Compare February 13, 2023 12:49
(stellar_stroops * CONVERSION_RATE as i64) as u128
let conversion_rate = i64::try_from(CONVERSION_RATE).unwrap_or(i64::MAX);

let value = stellar_stroops * conversion_rate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should even use saturating_mul() here, just to be safe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b-yap WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@b-yap b-yap requested a review from ebma February 14, 2023 12:29
@ebma ebma merged commit 75c7f7a into 242-fix-minor-issues Feb 14, 2023
@ebma ebma deleted the 242-LIP-01_unsafe_integer_cast branch February 14, 2023 15:14
b-yap added a commit that referenced this pull request Feb 14, 2023
…plementation (#256)

* if conversion rate is too big for i64, set it to what its max is.

if the i64 value reaches negative, make it zero for u128

* https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371
b-yap added a commit that referenced this pull request Feb 15, 2023
…plementation (#256)

* if conversion rate is too big for i64, set it to what its max is.

if the i64 value reaches negative, make it zero for u128

* https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371
ebma added a commit that referenced this pull request Feb 16, 2023
* 242 removing unnecessary conversion of a vector (#247)

* fix weight for mint tokens in redeem pallet (#259)

* first iteration (#258)

* TryFrom `CurrencyId` Implementations Contain Repeated Code (#249)

* 242 - secret exposed in cli (#255)

* first iteration

* update the readme , for the `stellar_vault_secret_key_filepath`.

* add the example secret key file

* applying cargo fmt

* update the readme

* if conversion rate is too big for i64, set it to what its max is.

if the i64 value reaches negative, make it zero for u128

* Revert "if conversion rate is too big for i64, set it to what its max is."

This reverts commit 399f175.

* since DOT is already at 20, 20 should not fail. changed it to 30.

* 242 - unsafe integer cast for `BalanceConversion`'s `StaticLookUp` implementation (#256)

* if conversion rate is too big for i64, set it to what its max is.

if the i64 value reaches negative, make it zero for u128

* https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371

* fix metadata-standalone.scale

* updated metadata scala

* TryFrom `CurrencyId` Implementations Contain Repeated Code (#249)

* Update metadata-standalone.scale

---------

Co-authored-by: B. Yap <2826165+b-yap@users.noreply.github.com>
Co-authored-by: cr4pt0 <102041955+cr4pt0@users.noreply.github.com>
ebma added a commit that referenced this pull request Feb 23, 2023
* 242 removing unnecessary conversion of a vector (#247)

* fix weight for mint tokens in redeem pallet (#259)

* first iteration (#258)

* TryFrom `CurrencyId` Implementations Contain Repeated Code (#249)

* 242 - secret exposed in cli (#255)

* first iteration

* update the readme , for the `stellar_vault_secret_key_filepath`.

* add the example secret key file

* applying cargo fmt

* update the readme

* if conversion rate is too big for i64, set it to what its max is.

if the i64 value reaches negative, make it zero for u128

* Revert "if conversion rate is too big for i64, set it to what its max is."

This reverts commit 399f175.

* since DOT is already at 20, 20 should not fail. changed it to 30.

* 242 - unsafe integer cast for `BalanceConversion`'s `StaticLookUp` implementation (#256)

* if conversion rate is too big for i64, set it to what its max is.

if the i64 value reaches negative, make it zero for u128

* https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371

* fix metadata-standalone.scale

* updated metadata scala

* TryFrom `CurrencyId` Implementations Contain Repeated Code (#249)

* Update metadata-standalone.scale

---------

Co-authored-by: B. Yap <2826165+b-yap@users.noreply.github.com>
Co-authored-by: cr4pt0 <102041955+cr4pt0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants